Mobile phone ordering project source code

Mobile phone ordering project source code

Source code introduction: Mobile phone ordering project source code

Source code effect:

Source code snippet:

  1. package com.jeremyfeinstein.slidingmenu.lib;
  2.   
  3. import java.lang.reflect.Method;
  4.   
  5. import android.annotation.SuppressLint;
  6. import android.annotation.TargetApi;
  7. import android.app.Activity;
  8. import android.content.Context;
  9. import android.content.res.TypedArray;
  10. import android.graphics.Bitmap;
  11. import android.graphics.BitmapFactory;
  12. import android.graphics.Canvas;
  13. import android.graphics.Point;
  14. import android.graphics.Rect;
  15. import android.graphics.drawable.Drawable;
  16. import android.os.Build;
  17. import android.os.Handler;
  18. import android.os.Parcel;
  19. import android.os.Parcelable;
  20. import android.util.AttributeSet;
  21. import android.util.Log;
  22. import android.view.Display;
  23. import android.view.LayoutInflater;
  24. import android.view.View;
  25. import android.view.ViewGroup;
  26. import android.view.WindowManager;
  27. import android.widget.FrameLayout;
  28. import android.widget.RelativeLayout;
  29.   
  30. import com.jeremyfeinstein.slidingmenu.lib.CustomViewAbove.OnPageChangeListener;
  31.   
  32. public   class SlidingMenu extends RelativeLayout {
  33.   
  34. private   static   final String TAG = SlidingMenu. class .getSimpleName();
  35.   
  36. public   static   final   int SLIDING_WINDOW = 0 ;
  37. public   static   final   int SLIDING_CONTENT = 1 ;
  38. private   boolean mActionbarOverlay = false ;
  39.   
  40. /** Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe
  41. * gesture on the screen's margin
  42. */  
  43. public   static   final   int TOUCHMODE_MARGIN = 0 ;
  44.   
  45. /** Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe
  46. * gesture anywhere on the screen
  47. */  
  48. public   static   final   int TOUCHMODE_FULLSCREEN = 1 ;
  49.   
  50. /** Constant value for use with setTouchModeAbove(). Denies the SlidingMenu to be opened with a swipe
  51. * gesture
  52. */  
  53. public   static   final   int TOUCHMODE_NONE = 2 ;
  54.   
  55. /** Constant value for use with setMode(). Puts the menu to the left of the content.
  56. */  
  57. public   static   final   int LEFT = 0 ;
  58.   
  59. /** Constant value for use with setMode(). Puts the menu to the right of the content.
  60. */  
  61. public   static   final   int RIGHT = 1 ;
  62.   
  63. /** Constant value for use with setMode(). Puts menus to the left and right of the content.
  64. */  
  65. public   static   final   int LEFT_RIGHT = 2 ;
  66.   
  67. private CustomViewAbove mViewAbove;
  68.   
  69. private CustomViewBehind mViewBehind;
  70.   
  71. private OnOpenListener mOpenListener;
  72.       
  73. private OnOpenListener mSecondaryOpenListner;
  74.   
  75. private OnCloseListener mCloseListener;
  76.   
  77. /**
  78. * The listener interface for receiving onOpen events.
  79. * The class that is interested in processing a onOpen
  80. * event implements this interface, and the object created
  81. * with that class is registered with a component using the
  82. * component's <code>addOnOpenListener<code> method. When
  83. * the onOpen event occurs, that object's appropriate
  84. * method is invoked
  85. */  
  86. public   interface OnOpenListener {
  87.   
  88. /**
  89. * On open.
  90. */  
  91. public   void onOpen();
  92. }
  93.   
  94. /**
  95. * The listener interface for receiving onOpened events.
  96. * The class that is interested in processing a onOpened
  97. * event implements this interface, and the object created
  98. * with that class is registered with a component using the
  99. * component's <code>addOnOpenedListener<code> method. When
  100. * the onOpened event occurs, that object's appropriate
  101. * method is invoked.
  102. *
  103. * @see OnOpenedEvent
  104. */  
  105. public   interface OnOpenedListener {
  106.   
  107. /**
  108. * On opened.
  109. */  
  110. public   void onOpened();
  111. }
  112.   
  113. /**
  114. * The listener interface for receiving onClose events.
  115. * The class that is interested in processing a onClose
  116. * event implements this interface, and the object created
  117. * with that class is registered with a component using the
  118. * component's <code>addOnCloseListener<code> method. When
  119. * the onClose event occurs, that object's appropriate
  120. * method is invoked.
  121. *
  122. * @see OnCloseEvent
  123. */  
  124. public   interface OnCloseListener {
  125.   
  126. /**
  127. * On close.
  128. */  
  129. public   void onClose();
  130. }
  131.   
  132. /**
  133. * The listener interface for receiving onClosed events.
  134. * The class that is interested in processing a onClosed
  135. * event implements this interface, and the object created
  136. * with that class is registered with a component using the
  137. * component's <code>addOnClosedListener<code> method. When
  138. * the onClosed event occurs, that object's appropriate
  139. * method is invoked.
  140. *
  141. * @see OnClosedEvent
  142. */  
  143. public   interface OnClosedListener {
  144.   
  145. /**
  146. * On closed.
  147. */  
  148. public   void onClosed();
  149. }
  150.   
  151. /**
  152. * The Interface CanvasTransformer.
  153. */  
  154. public   interface CanvasTransformer {
  155.   
  156. /**
  157. * Transform canvas.
  158. *
  159. * @param canvas the canvas
  160. * @param percentOpen the percent open
  161. */  
  162. public   void transformCanvas(Canvas canvas, float percentOpen);
  163. }
  164.   
  165. /**
  166. * Instantiates a new SlidingMenu.
  167. *
  168. * @param context the associated Context
  169. */  
  170. public SlidingMenu(Context context) {
  171. this (context, null );
  172. }
  173.   
  174. /**
  175. * Instantiates a new SlidingMenu and attach to Activity.
  176. *
  177. * @param activity the activity to attach slidingmenu
  178. * @param slideStyle the slidingmenu style
  179. */  
  180. public SlidingMenu(Activity activity, int slideStyle) {
  181. this (activity, null );
  182. this .attachToActivity(activity, slideStyle);
  183. }
  184.   
  185. /**
  186. * Instantiates a new SlidingMenu.
  187. *
  188. * @param context the associated Context
  189. * @param attrs the attrs
  190. */  
  191. public SlidingMenu(Context context, AttributeSet attrs) {
  192. this (context, attrs, 0 );
  193. }
  194.   
  195. /**
  196. * Instantiates a new SlidingMenu.
  197. *
  198. * @param context the associated Context
  199. * @param attrs the attrs
  200. * @param defStyle the def style
  201. */  
  202. public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
  203. super (context, attrs, defStyle);
  204.           
  205. LayoutParams behindParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  206. mViewBehind = new CustomViewBehind(context);
  207. addView(mViewBehind, behindParams);
  208. LayoutParams aboveParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  209. mViewAbove = new CustomViewAbove(context);
  210. addView(mViewAbove, aboveParams);
  211. // register the CustomViewBehind with the CustomViewAbove  
  212. mViewAbove.setCustomViewBehind(mViewBehind);
  213. mViewBehind.setCustomViewAbove(mViewAbove);
  214. mViewAbove.setOnPageChangeListener( new OnPageChangeListener() {
  215. public   static   final   int POSITION_OPEN = 0 ;
  216. public   static   final   int POSITION_CLOSE = 1 ;
  217. public   static   final   int POSITION_SECONDARY_OPEN = 2 ;
  218.   
  219. public   void onPageScrolled( int position, float positionOffset,
  220. int positionOffsetPixels) { }
  221.   
  222. public   void onPageSelected( int position) {
  223. if (position == POSITION_OPEN && mOpenListener != null ) {
  224. mOpenListener.onOpen();
  225. } else   if (position == POSITION_CLOSE && mCloseListener != null ) {
  226. mCloseListener.onClose();
  227. } else   if (position == POSITION_SECONDARY_OPEN && mSecondaryOpenListner != null ) {
  228. mSecondaryOpenListner.onOpen();
  229. }
  230. }
  231. });
  232.   
  233. // now style everything!  
  234. TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingMenu);
  235. // set the above and behind views if defined in xml  
  236. int mode = ta.getInt(R.styleable.SlidingMenu_mode, LEFT);
  237. setMode(mode);
  238. int viewAbove = ta.getResourceId(R.styleable.SlidingMenu_viewAbove, - 1 );
  239. if (viewAbove != - 1 ) {
  240. setContent(viewAbove);
  241. } else {
  242. setContent( new FrameLayout(context));
  243. }
  244. int viewBehind = ta.getResourceId(R.styleable.SlidingMenu_viewBehind, - 1 );
  245. if (viewBehind != - 1 ) {
  246. setMenu(viewBehind);
  247. } else {
  248. setMenu( new FrameLayout(context));
  249. }
  250. int touchModeAbove = ta.getInt(R.styleable.SlidingMenu_touchModeAbove, TOUCHMODE_MARGIN);
  251. setTouchModeAbove(touchModeAbove);
  252. int touchModeBehind = ta.getInt(R.styleable.SlidingMenu_touchModeBehind, TOUCHMODE_MARGIN);
  253. setTouchModeBehind(touchModeBehind);
  254.   
  255. int offsetBehind = ( int ) ta.getDimension(R.styleable.SlidingMenu_behindOffset, - 1 );
  256. int widthBehind = ( int ) ta.getDimension(R.styleable.SlidingMenu_behindWidth, - 1 );
  257. if (offsetBehind != - 1 && widthBehind != - 1 )
  258. throw   new IllegalStateException( "Cannot set both behindOffset and behindWidth for a SlidingMenu" );
  259. else   if (offsetBehind != - 1 )
  260. setBehindOffset(offsetBehind);
  261. else   if (widthBehind != - 1 )
  262. setBehindWidth(widthBehind);
  263. else  
  264. setBehindOffset( 0 );
  265. float scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_behindScrollScale, 0.33f );
  266. setBehindScrollScale(scrollOffsetBehind);
  267. int shadowRes = ta.getResourceId(R.styleable.SlidingMenu_shadowDrawable, - 1 );
  268. if (shadowRes != - 1 ) {
  269. setShadowDrawable(shadowRes);
  270. }
  271. int shadowWidth = ( int ) ta.getDimension(R.styleable.SlidingMenu_shadowWidth, 0 );
  272. setShadowWidth(shadowWidth);
  273. boolean fadeEnabled = ta.getBoolean(R.styleable.SlidingMenu_fadeEnabled, true );
  274. setFadeEnabled(fadeEnabled);
  275. float fadeDeg = ta.getFloat(R.styleable.SlidingMenu_fadeDegree, 0 .33f);
  276. setFadeDegree(fadeDeg);
  277. boolean selectorEnabled = ta.getBoolean(R.styleable.SlidingMenu_selectorEnabled, false );
  278. setSelectorEnabled(selectorEnabled);
  279. int selectorRes = ta.getResourceId(R.styleable.SlidingMenu_selectorDrawable, - 1 );
  280. if (selectorRes != - 1 )
  281. setSelectorDrawable(selectorRes);
  282. ta.recycle();
  283. }
  284.   
  285. /**
  286. * Attaches the SlidingMenu to an entire Activity
  287. *
  288. * @param activity the Activity
  289. * @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW
  290. */  
  291. public   void attachToActivity(Activity activity, int slideStyle) {
  292. attachToActivity(activity, slideStyle, false );
  293. }
  294.   
  295. /**
  296. * Attaches the SlidingMenu to an entire Activity
  297. *
  298. * @param activity the Activity
  299. * @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW
  300. * @param actionbarOverlay whether or not the ActionBar is overlaid
  301. */  
  302. public   void attachToActivity(Activity activity, int slideStyle, boolean actionbarOverlay) {
  303. if (slideStyle != SLIDING_WINDOW && slideStyle != SLIDING_CONTENT)
  304. throw   new IllegalArgumentException( "slideStyle must be either SLIDING_WINDOW or SLIDING_CONTENT" );
  305.   
  306. if (getParent() != null )
  307. throw   new IllegalStateException( "This SlidingMenu appears to already be attached" );
  308.   
  309. // get the window background  
  310. TypedArray a = activity.getTheme().obtainStyledAttributes( new   int [] {android.R.attr.windowBackground});
  311. int background = a.getResourceId( 0 , 0 );
  312. a.recycle();
  313.   
  314. switch (slideStyle) {
  315. case SLIDING_WINDOW:
  316. mActionbarOverlay = false ;
  317. ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
  318. ViewGroup decorChild = (ViewGroup) decor.getChildAt( 0 );
  319. // save ActionBar themes that have transparent assets  
  320. decorChild.setBackgroundResource(background);
  321. decor.removeView(decorChild);
  322. decor.addView( this );
  323. setContent(decorChild);
  324. break ;
  325. case SLIDING_CONTENT:
  326. mActionbarOverlay = actionbarOverlay;
  327. // take the above view out of  
  328. ViewGroup contentParent = (ViewGroup)activity.findViewById(android.R.id.content);
  329. View content = contentParent.getChildAt( 0 );
  330. contentParent.removeView(content);
  331. contentParent.addView( this );
  332. setContent(content);
  333. // save people from having transparent backgrounds  
  334. if (content.getBackground() == null )
  335. content.setBackgroundResource(background);
  336. break ;
  337. }
  338. }
  339.   
  340. /**
  341. * Set the above view content from a layout resource. The resource will be inflated, adding all top-level views
  342. * to the above view.
  343. *
  344. * @param res the new content
  345. */  
  346. public   void setContent( int res) {
  347. setContent(LayoutInflater.from(getContext()).inflate(res, null ));
  348. }
  349.   
  350. /**
  351. * Set the above view content to the given View.
  352. *
  353. * @param view The desired content to display.
  354. */  
  355. public   void setContent(View view) {
  356. mViewAbove.setContent(view);
  357. showContent();
  358. }
  359.   
  360. /**
  361. * Retrieves the current content.
  362. * @return the current content
  363. */  
  364. public View getContent() {
  365. return mViewAbove.getContent();
  366. }
  367.   
  368. /**
  369. * Set the behind view (menu) content from a layout resource. The resource will be inflated, adding all top-level views
  370. * to the behind view.
  371. *
  372. * @param res the new content
  373. */  
  374. public   void setMenu( int res) {
  375. setMenu(LayoutInflater.from(getContext()).inflate(res, null ));
  376. }
  377.   
  378. /**
  379. * Set the behind view (menu) content to the given View.
  380. *
  381. * @param view The desired content to display.
  382. */  
  383. public   void setMenu(View v) {
  384. mViewBehind.setContent(v);
  385. }
  386.   
  387. /**
  388. * Retrieves the main menu.
  389. * @return the main menu
  390. */  
  391. public View getMenu() {
  392. return mViewBehind.getContent();
  393. }
  394.   
  395. /**
  396. * Set the secondary behind view (right menu) content from a layout resource. The resource will be inflated, adding all top-level views
  397. * to the behind view.
  398. *
  399. * @param res the new content
  400. */  
  401. public   void setSecondaryMenu( int res) {
  402. setSecondaryMenu(LayoutInflater.from(getContext()).inflate(res, null ));
  403. }
  404.   
  405. /**
  406. * Set the secondary behind view (right menu) content to the given View.
  407. *
  408. * @param view The desired content to display.
  409. */  
  410. public   void setSecondaryMenu(View v) {
  411. mViewBehind.setSecondaryContent(v);
  412. // mViewBehind.invalidate();  
  413. }
  414.   
  415. /**
  416. * Retrieves the current secondary menu (right).
  417. * @return the current menu
  418. */  
  419. public View getSecondaryMenu() {
  420. return mViewBehind.getSecondaryContent();
  421. }
  422.   
  423.   
  424. /**
  425. * Sets the sliding enabled.
  426. *
  427. * @param b true to enable sliding, false to disable it.
  428. */  
  429. public   void setSlidingEnabled( boolean b) {
  430. mViewAbove.setSlidingEnabled(b);
  431. }
  432.   
  433. /**
  434. * Checks if sliding is enabled.
  435. *
  436. * @return true, if is sliding enabled
  437. */  
  438. public   boolean isSlidingEnabled() {
  439. return mViewAbove.isSlidingEnabled();
  440. }
  441.   
  442. /**
  443. * Sets which side the SlidingMenu should appear on.
  444. * @param mode must be either SlidingMenu.LEFT or SlidingMenu.RIGHT
  445. */  
  446. public   void setMode( int mode) {
  447. if (mode != LEFT && mode != RIGHT && mode != LEFT_RIGHT) {
  448. throw   new IllegalStateException( "SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT" );
  449. }
  450. mViewBehind.setMode(mode);
  451. }
  452.   
  453. /**
  454. * Returns the current side that the SlidingMenu is on.
  455. * @return the current mode, either SlidingMenu.LEFT or SlidingMenu.RIGHT
  456. */  
  457. public   int getMode() {
  458. return mViewBehind.getMode();
  459. }
  460.   
  461. /**
  462. * Sets whether or not the SlidingMenu is in static mode (ie nothing is moving and everything is showing)
  463. *
  464. * @param b true to set static mode, false to disable static mode.
  465. */  
  466. public   void setStatic( boolean b) {
  467. if (b) {
  468. setSlidingEnabled( false );
  469. mViewAbove.setCustomViewBehind( null );
  470. mViewAbove.setCurrentItem( 1 );
  471. // mViewBehind.setCurrentItem(0);  
  472. } else {
  473. mViewAbove.setCurrentItem( 1 );
  474. // mViewBehind.setCurrentItem(1);  
  475. mViewAbove.setCustomViewBehind(mViewBehind);
  476. setSlidingEnabled( true );
  477. }
  478. }
  479.   
  480. /**
  481. * Opens the menu and shows the menu view.
  482. */  
  483. public   void showMenu() {
  484. showMenu( true );
  485. }
  486.   
  487. /**
  488. * Opens the menu and shows the menu view.
  489. *
  490. * @param animate true to animate the transition, false to ignore animation
  491. */  
  492. public   void showMenu( boolean animate) {
  493. mViewAbove.setCurrentItem( 0 , animate);
  494. }
  495.   
  496. /**
  497. * Opens the menu and shows the secondary menu view. Will default to the regular menu
  498. * if there is only one.
  499. */  
  500. public   void showSecondaryMenu() {
  501. showSecondaryMenu( true );
  502. }
  503.   
  504. /**
  505. * Opens the menu and shows the secondary (right) menu view. Will default to the regular menu
  506. * if there is only one.
  507. *
  508. * @param animate true to animate the transition, false to ignore animation
  509. */  
  510. public   void showSecondaryMenu( boolean animate) {
  511. mViewAbove.setCurrentItem( 2 , animate);
  512. }
  513.   
  514. /**
  515. * Closes the menu and shows the above view.
  516. */  
  517. public   void showContent() {
  518. showContent( true );
  519. }
  520.   
  521. /**
  522. * Closes the menu and shows the above view.
  523. *
  524. * @param animate true to animate the transition, false to ignore animation
  525. */  
  526. public   void showContent( boolean animate) {
  527. mViewAbove.setCurrentItem( 1 , animate);
  528. }
  529.   
  530. /**
  531. * Toggle the SlidingMenu. If it is open, it will be closed, and vice versa.
  532. */  
  533. public   void toggle() {
  534. toggle( true );
  535. }
  536.   
  537. /**
  538. * Toggle the SlidingMenu. If it is open, it will be closed, and vice versa.
  539. *
  540. * @param animate true to animate the transition, false to ignore animation
  541. */  
  542. public   void toggle( boolean animate) {
  543. if (isMenuShowing()) {
  544. showContent(animate);
  545. } else {
  546. showMenu(animate);
  547. }
  548. }
  549.   
  550. /**
  551. * Checks if is the behind view showing.
  552. *
  553. * @return Whether or not the behind view is showing
  554. */  
  555. public   boolean isMenuShowing() {
  556. return mViewAbove.getCurrentItem() == 0 || mViewAbove.getCurrentItem() == 2 ;
  557. }
  558.       
  559. /**
  560. * Checks if is the behind view showing.
  561. *
  562. * @return Whether or not the behind view is showing
  563. */  
  564. public   boolean isSecondaryMenuShowing() {
  565. return mViewAbove.getCurrentItem() == 2 ;
  566. }
  567.   
  568. /**
  569. * Gets the behind offset.
  570. *
  571. * @return The margin on the right of the screen that the behind view scrolls to
  572. */  
  573. public   int getBehindOffset() {
  574. return ((RelativeLayout.LayoutParams)mViewBehind.getLayoutParams()).rightMargin;
  575. }
  576.   
  577. /**
  578. * Sets the behind offset.
  579. *
  580. * @param i The margin, in pixels, on the right of the screen that the behind view scrolls to.
  581. */  
  582. public   void setBehindOffset( int i) {
  583. // RelativeLayout.LayoutParams params = ((RelativeLayout.LayoutParams)mViewBehind.getLayoutParams());  
  584. // int bottom = params.bottomMargin;  
  585. // int top = params.topMargin;  
  586. // int left = params.leftMargin;  
  587. // params.setMargins(left, top, i, bottom);  
  588. mViewBehind.setWidthOffset(i);
  589. }
  590.   
  591. /**
  592. * Sets the behind offset.
  593. *
  594. * @param resID The dimension resource id to be set as the behind offset.
  595. * The menu, when open, will leave this width margin on the right of the screen.
  596. */  
  597. public   void setBehindOffsetRes( int resID) {
  598. int i = ( int ) getContext().getResources().getDimension(resID);
  599. setBehindOffset(i);
  600. }
  601.   
  602. /**
  603. * Sets the above offset.
  604. *
  605. * @param i the new above offset, in pixels
  606. */  
  607. public   void setAboveOffset( int i) {
  608. mViewAbove.setAboveOffset(i);
  609. }
  610.   
  611. /**
  612. * Sets the above offset.
  613. *
  614. * @param resID The dimension resource id to be set as the above offset.
  615. */  
  616. public   void setAboveOffsetRes( int resID) {
  617. int i = ( int ) getContext().getResources().getDimension(resID);
  618. setAboveOffset(i);
  619. }
  620.   
  621. /**
  622. * Sets the behind width.
  623. *
  624. * @param i The width the Sliding Menu will open to, in pixels
  625. */  
  626. @SuppressWarnings ( "deprecation" )
  627. public   void setBehindWidth( int i) {
  628. int width;
  629. Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
  630. .getDefaultDisplay();
  631. try {
  632. Class<!--?--> cls = Display.class ;
  633. Class<!--?-->[] parameterTypes = {Point. class };
  634. Point parameter = new Point();
  635. Method method = cls.getMethod( "getSize" , parameterTypes);
  636. method.invoke(display, parameter);
  637. width = parameter.x;
  638. } catch (Exception e) {
  639. width = display.getWidth();
  640. }
  641. setBehindOffset(width-i);
  642. }
  643.   
  644. /**
  645. * Sets the behind width.
  646. *
  647. * @param res The dimension resource id to be set as the behind width offset.
  648. * The menu, when open, will open this wide.
  649. */  
  650. public   void setBehindWidthRes( int res) {
  651. int i = ( int ) getContext().getResources().getDimension(res);
  652. setBehindWidth(i);
  653. }
  654.   
  655. /**
  656. * Gets the behind scroll scale.
  657. *
  658. * @return The scale of the parallax scroll
  659. */  
  660. public   float getBehindScrollScale() {
  661. return mViewBehind.getScrollScale();
  662. }
  663.       
  664. /**
  665. * Gets the touch mode margin threshold
  666. * @return the touch mode margin threshold
  667. */  
  668. public   int getTouchmodeMarginThreshold() {
  669. return mViewBehind.getMarginThreshold();
  670. }
  671.       
  672. /**
  673. * Set the touch mode margin threshold
  674. * @param touchmodeMarginThreshold
  675. */  
  676. public   void setTouchmodeMarginThreshold( int touchmodeMarginThreshold) {
  677. mViewBehind.setMarginThreshold(touchmodeMarginThreshold);
  678. }
  679.   
  680. /**
  681. * Sets the behind scroll scale.
  682. *
  683. * @param f The scale of the parallax scroll (ie 1.0f scrolls 1 pixel for every
  684. * 1 pixel that the above view scrolls and 0.0f scrolls 0 pixels)
  685. */  
  686. public   void setBehindScrollScale( float f) {
  687. if (f < 0 && f > 1 )
  688. throw   new IllegalStateException( "ScrollScale must be between 0 and 1" );
  689. mViewBehind.setScrollScale(f);
  690. }
  691.   
  692. /**
  693. * Sets the behind canvas transformer.
  694. *
  695. * @param t the new behind canvas transformer
  696. */  
  697. public   void setBehindCanvasTransformer(CanvasTransformer t) {
  698. mViewBehind.setCanvasTransformer(t);
  699. }
  700.   
  701. /**
  702. * Gets the touch mode above.
  703. *
  704. * @return the touch mode above
  705. */  
  706. public   int getTouchModeAbove() {
  707. return mViewAbove.getTouchMode();
  708. }
  709.   
  710. /**
  711. * Controls whether the SlidingMenu can be opened with a swipe gesture.
  712. * Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN},
  713. * or {@link #TOUCHMODE_NONE TOUCHMODE_NONE}
  714. *
  715. * @param i the new touch mode
  716. */  
  717. public   void setTouchModeAbove( int i) {
  718. if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN
  719. && i != TOUCHMODE_NONE) {
  720. throw   new IllegalStateException( "TouchMode must be set to either" +
  721. "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE." );
  722. }
  723. mViewAbove.setTouchMode(i);
  724. }
  725.   
  726. /**
  727. * Controls whether the SlidingMenu can be opened with a swipe gesture.
  728. * Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN},
  729. * or {@link #TOUCHMODE_NONE TOUCHMODE_NONE}
  730. *
  731. * @param i the new touch mode
  732. */  
  733. public   void setTouchModeBehind( int i) {
  734. if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN
  735. && i != TOUCHMODE_NONE) {
  736. throw   new IllegalStateException( "TouchMode must be set to either" +
  737. "TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE." );
  738. }
  739. mViewBehind.setTouchMode(i);
  740. }
  741.   
  742. /**
  743. * Sets the shadow drawable.
  744. *
  745. * @param resId the resource ID of the new shadow drawable
  746. */  
  747. public   void setShadowDrawable( int resId) {
  748. setShadowDrawable(getContext().getResources().getDrawable(resId));
  749. }
  750.   
  751. /**
  752. * Sets the shadow drawable.
  753. *
  754. * @param d the new shadow drawable
  755. */  
  756. public   void setShadowDrawable(Drawable d) {
  757. mViewBehind.setShadowDrawable(d);
  758. }
  759.   
  760. /**
  761. * Sets the secondary (right) shadow drawable.
  762. *
  763. * @param resId the resource ID of the new shadow drawable
  764. */  
  765. public   void setSecondaryShadowDrawable( int resId) {
  766. setSecondaryShadowDrawable(getContext().getResources().getDrawable(resId));
  767. }
  768.   
  769. /**
  770. * Sets the secondary (right) shadow drawable.
  771. *
  772. * @param d the new shadow drawable
  773. */  
  774. public   void setSecondaryShadowDrawable(Drawable d) {
  775. mViewBehind.setSecondaryShadowDrawable(d);
  776. }
  777.   
  778. /**
  779. * Sets the shadow width.
  780. *
  781. * @param resId The dimension resource id to be set as the shadow width.
  782. */  
  783. public   void setShadowWidthRes( int resId) {
  784. setShadowWidth(( int )getResources().getDimension(resId));
  785. }
  786.   
  787. /**
  788. * Sets the shadow width.
  789. *
  790. * @param pixels the new shadow width, in pixels
  791. */  
  792. public   void setShadowWidth( int pixels) {
  793. mViewBehind.setShadowWidth(pixels);
  794. }
  795.   
  796. /**
  797. * Enables or disables the SlidingMenu's fade in and out
  798. *
  799. * @param b true to enable fade, false to disable it
  800. */  
  801. public   void setFadeEnabled( boolean b) {
  802. mViewBehind.setFadeEnabled(b);
  803. }
  804.   
  805. /**
  806. * Sets how much the SlidingMenu fades in and out. Fade must be enabled, see
  807. * {@link #setFadeEnabled(boolean) setFadeEnabled(boolean)}
  808. *
  809. * @param f the new fade degree, between 0.0f and 1.0f
  810. */  
  811. public   void setFadeDegree( float f) {
  812. mViewBehind.setFadeDegree(f);
  813. }
  814.   
  815. /**
  816. * Enables or disables whether the selector is drawn
  817. *
  818. * @param b true to draw the selector, false to not draw the selector
  819. */  
  820. public   void setSelectorEnabled( boolean b) {
  821. mViewBehind.setSelectorEnabled( true );
  822. }
  823.   
  824. /**
  825. * Sets the selected view. The selector will be drawn here
  826. *
  827. * @param v the new selected view
  828. */  
  829. public   void setSelectedView(View v) {
  830. mViewBehind.setSelectedView(v);
  831. }
  832.   
  833. /**
  834. * Sets the selector drawable.
  835. *
  836. * @param res a resource ID for the selector drawable
  837. */  
  838. public   void setSelectorDrawable( int res) {
  839. mViewBehind.setSelectorBitmap(BitmapFactory.decodeResource(getResources(), res));
  840. }
  841.   
  842. /**
  843. * Sets the selector drawable.
  844. *
  845. * @param b the new selector bitmap
  846. */  
  847. public   void setSelectorBitmap(Bitmap b) {
  848. mViewBehind.setSelectorBitmap(b);
  849. }
  850.   
  851. /**
  852. * Add a View ignored by the Touch Down event when mode is Fullscreen
  853. *
  854. * @param v a view to be ignored
  855. */  
  856. public   void addIgnoredView(View v) {
  857. mViewAbove.addIgnoredView(v);
  858. }
  859.   
  860. /**
  861. * Remove a View ignored by the Touch Down event when mode is Fullscreen
  862. *
  863. * @param v a view not wanted to be ignored anymore
  864. */  
  865. public   void removeIgnoredView(View v) {
  866. mViewAbove.removeIgnoredView(v);
  867. }
  868.   
  869. /**
  870. * Clear the list of Views ignored by the Touch Down event when mode is Fullscreen
  871. */  
  872. public   void clearIgnoredViews() {
  873. mViewAbove.clearIgnoredViews();
  874. }
  875.   
  876. /**
  877. * Sets the OnOpenListener. {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the SlidingMenu is opened
  878. *
  879. * @param listener the new OnOpenListener
  880. */  
  881. public   void setOnOpenListener(OnOpenListener listener) {
  882. //mViewAbove.setOnOpenListener(listener);  
  883. mOpenListener = listener;
  884. }
  885.   
  886.       
  887. /**
  888. * Sets the OnOpenListner for secondary menu {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the secondary SlidingMenu is opened
  889. *
  890. * @param listener the new OnOpenListener
  891. */  
  892.       
  893. public   void setSecondaryOnOpenListner(OnOpenListener listener) {
  894. mSecondaryOpenListner = listener;
  895. }
  896.       
  897. /**
  898. * Sets the OnCloseListener. {@link OnCloseListener#onClose() OnCloseListener.onClose()} will be called when any one of the SlidingMenu is closed
  899. *
  900. * @param listener the new setOnCloseListener
  901. */  
  902. public   void setOnCloseListener(OnCloseListener listener) {
  903. //mViewAbove.setOnCloseListener(listener);  
  904. mCloseListener = listener;
  905. }
  906.   
  907. /**
  908. * Sets the OnOpenedListener. {@link OnOpenedListener#onOpened() OnOpenedListener.onOpened()} will be called after the SlidingMenu is opened
  909. *
  910. * @param listener the new OnOpenedListener
  911. */  
  912. public   void setOnOpenedListener(OnOpenedListener listener) {
  913. mViewAbove.setOnOpenedListener(listener);
  914. }
  915.   
  916. /**
  917. * Sets the OnClosedListener. {@link OnClosedListener#onClosed() OnClosedListener.onClosed()} will be called after the SlidingMenu is closed
  918. *
  919. * @param listener the new OnClosedListener
  920. */  
  921. public   void setOnClosedListener(OnClosedListener listener) {
  922. mViewAbove.setOnClosedListener(listener);
  923. }
  924.   
  925. public   static   class SavedState extends BaseSavedState {
  926.   
  927. private   final   int mItem;
  928.   
  929. public SavedState(Parcelable superState, int item) {
  930. super (superState);
  931. mItem = item;
  932. }
  933.   
  934. private SavedState(Parcel in) {
  935. super (in);
  936. mItem = in.readInt();
  937. }
  938.   
  939. public   int getItem() {
  940. return mItem;
  941. }
  942.   
  943. /* (non-Javadoc)
  944. * @see android.view.AbsSavedState#writeToParcel(android.os.Parcel, int)
  945. */  
  946. public   void writeToParcel(Parcel out, int flags) {
  947. super .writeToParcel(out, flags);
  948. out.writeInt(mItem);
  949. }
  950.   
  951. public   static   final Parcelable.Creator<savedstate> CREATOR =
  952. new Parcelable.Creator<savedstate>() {
  953. public SavedState createFromParcel(Parcel in) {
  954. return   new SavedState(in);
  955. }
  956.   
  957. public SavedState[] newArray( int size) {
  958. return   new SavedState[size];
  959. }
  960. };
  961.   
  962. }
  963.   
  964. /* (non-Javadoc)
  965. * @see android.view.View#onSaveInstanceState()
  966. */  
  967. @Override  
  968. protected Parcelable onSaveInstanceState() {
  969. Parcelable superState = super .onSaveInstanceState();
  970. SavedState ss = new SavedState(superState, mViewAbove.getCurrentItem());
  971. return ss;
  972. }
  973.   
  974. /* (non-Javadoc)
  975. * @see android.view.View#onRestoreInstanceState(android.os.Parcelable)
  976. */  
  977. @Override  
  978. protected   void onRestoreInstanceState(Parcelable state) {
  979. SavedState ss = (SavedState)state;
  980. super .onRestoreInstanceState(ss.getSuperState());
  981. mViewAbove.setCurrentItem(ss.getItem());
  982. }
  983.   
  984. /* (non-Javadoc)
  985. * @see android.view.ViewGroup#fitSystemWindows(android.graphics.Rect)
  986. */  
  987. @SuppressLint ( "NewApi" )
  988. @Override  
  989. protected   boolean fitSystemWindows(Rect insets) {
  990. int leftPadding = insets.left;
  991. int rightPadding = insets.right;
  992. int topPadding = insets.top;
  993. int bottomPadding = insets.bottom;
  994. if (!mActionbarOverlay) {
  995. Log.v(TAG, "setting padding!" );
  996. setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
  997. }
  998. return   true ;
  999. }
  1000.   
  1001. @TargetApi (Build.VERSION_CODES.HONEYCOMB)
  1002. public   void manageLayers( float percentOpen) {
  1003. if (Build.VERSION.SDK_INT < 11 ) return ;
  1004.   
  1005. boolean layer = percentOpen > 0 .0f && percentOpen < 1 .0f;
  1006. final   int layerType = layer ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE;
  1007.   
  1008. if (layerType != getContent().getLayerType()) {
  1009. getHandler().post( new Runnable() {
  1010. public   void run() {
  1011. Log.v(TAG, "changing layerType. hardware? " + (layerType == View.LAYER_TYPE_HARDWARE));
  1012. getContent().setLayerType(layerType, null );
  1013. getMenu().setLayerType(layerType, null );
  1014. if (getSecondaryMenu() != null ) {
  1015. getSecondaryMenu().setLayerType(layerType, null );
  1016. }
  1017. }
  1018. });
  1019. }
  1020. }
  1021.   
  1022. }</savedstate></savedstate></code></code></code></code></code></code></code></code>

Download address: http://download..com/data/2125292

<<:  Imitation mall app

>>:  TopNews is a high imitation of the "Today's Headlines" client

Recommend

Marketing node reminder in February 2017, you must know!

The most important thing in building a brand is t...

Snail: Those around me who don’t live long are all too impatient.

I am Dong Dong Meow Talking animals are so fun! T...

The top ten e-books are free and completed, and the fantasy novels are ranked?

Due to the epidemic, many people are bored at hom...

The BUG in Marketing to Generation Z

Today, the main force of China's consumption ...

Brands must do these 5 things to stand out!

I believe that many people who do brand marketing...

Xiaohongshu promotion and traffic generation methods

Everyone is familiar with Xiaohongshu. It has dev...

Hisense will launch OLED TV and color TV competition will enter the high-end era

Recently, there have been rumors in the industry ...