Advertisement
iocoder

AndroView.java

Jan 26th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.03 KB | None | 0 0
  1. package com.hci.androview;
  2.  
  3. import com.hci.androview.util.SystemUiHider;
  4.  
  5. import android.annotation.TargetApi;
  6. import android.app.Activity;
  7. import android.os.Build;
  8. import android.os.Bundle;
  9. import android.os.Handler;
  10. import android.view.MotionEvent;
  11. import android.view.View;
  12. import android.widget.*;
  13. import android.content.*;
  14. import android.net.*;
  15. import android.provider.*;
  16. import android.database.*;
  17. import android.graphics.*;
  18.  
  19. /**
  20.  * An example full-screen activity that shows and hides the system UI (i.e.
  21.  * status bar and navigation/system bar) with user interaction.
  22.  *
  23.  * @see SystemUiHider
  24.  */
  25. public class FullscreenActivity extends Activity {
  26.     /**
  27.      * Whether or not the system UI should be auto-hidden after
  28.      * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
  29.      */
  30.     private static final boolean AUTO_HIDE = true;
  31.  
  32.     /**
  33.      * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
  34.      * user interaction before hiding the system UI.
  35.      */
  36.     private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
  37.  
  38.     /**
  39.      * If set, will toggle the system UI visibility upon interaction. Otherwise,
  40.      * will show the system UI visibility upon interaction.
  41.      */
  42.     private static final boolean TOGGLE_ON_CLICK = true;
  43.  
  44.     /**
  45.      * The flags to pass to {@link SystemUiHider#getInstance}.
  46.      */
  47.     private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
  48.  
  49.     /**
  50.      * The instance of the {@link SystemUiHider} for this activity.
  51.      */
  52.     private SystemUiHider mSystemUiHider;
  53.    
  54.     @Override
  55.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  56.         super.onActivityResult(requestCode, resultCode, data);
  57.         if (requestCode == 1 && resultCode == RESULT_OK && data != null) {
  58.            
  59.             Uri selectedImage = data.getData();
  60.            
  61.             try {
  62.                 Bitmap bm;
  63.                 bm = BitmapFactory.decodeStream(getContentResolver().openInputStream(selectedImage));
  64.                
  65.                 ImageView imageView = (ImageView) findViewById(R.id.img);
  66.                 imageView.setImageBitmap(bm);
  67.             } catch (Exception e) {
  68.                
  69.             }
  70.             //grantUriPermission("com.hci.androview", selectedImage, Intent.FLAG_GRANT_READ_URI_PERMISSION);
  71.  
  72.             // TextView txttest = (TextView) findViewById(R.id.txttest);
  73.  
  74.             //txttest.setText("Text: " + selectedImage.toString());          
  75.             /*
  76.             String[] filePathColumn = { MediaStore.Images.Media.DATA };
  77.  
  78.             Cursor cursor = getContentResolver().query(selectedImage,
  79.                     filePathColumn, null, null, null);
  80.             cursor.moveToFirst();
  81.  
  82.             int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
  83.             String picturePath = cursor.getString(columnIndex);
  84.             cursor.close();
  85.            
  86.            
  87.             imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));*/
  88.         }
  89.     }
  90.  
  91.  
  92.     @Override
  93.     protected void onCreate(Bundle savedInstanceState) {
  94.         super.onCreate(savedInstanceState);
  95.  
  96.         setContentView(R.layout.activity_fullscreen);
  97.  
  98.         final View controlsView = findViewById(R.id.fullscreen_content_controls);
  99.         final View contentView = findViewById(R.id.fullscreen_content);
  100.  
  101.         // Set up an instance of SystemUiHider to control the system UI for
  102.         // this activity.
  103.         mSystemUiHider = SystemUiHider.getInstance(this, contentView,
  104.                 HIDER_FLAGS);
  105.         mSystemUiHider.setup();
  106.         mSystemUiHider
  107.                 .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
  108.                     // Cached values.
  109.                     int mControlsHeight;
  110.                     int mShortAnimTime;
  111.  
  112.                     @Override
  113.                     @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
  114.                     public void onVisibilityChange(boolean visible) {
  115.                         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
  116.                             // If the ViewPropertyAnimator API is available
  117.                             // (Honeycomb MR2 and later), use it to animate the
  118.                             // in-layout UI controls at the bottom of the
  119.                             // screen.
  120.                             if (mControlsHeight == 0) {
  121.                                 mControlsHeight = controlsView.getHeight();
  122.                             }
  123.                             if (mShortAnimTime == 0) {
  124.                                 mShortAnimTime = getResources().getInteger(
  125.                                         android.R.integer.config_shortAnimTime);
  126.                             }
  127.                             controlsView
  128.                                     .animate()
  129.                                     .translationY(visible ? 0 : mControlsHeight)
  130.                                     .setDuration(mShortAnimTime);
  131.                         } else {
  132.                             // If the ViewPropertyAnimator APIs aren't
  133.                             // available, simply show or hide the in-layout UI
  134.                             // controls.
  135.                             controlsView.setVisibility(visible ? View.VISIBLE
  136.                                     : View.GONE);
  137.                         }
  138.  
  139.                         if (visible && AUTO_HIDE) {
  140.                             // Schedule a hide().
  141.                             delayedHide(AUTO_HIDE_DELAY_MILLIS);
  142.                         }
  143.                     }
  144.                 });
  145.  
  146.         // Set up the user interaction to manually show or hide the system UI.
  147.         contentView.setOnClickListener(new View.OnClickListener() {
  148.             @Override
  149.             public void onClick(View view) {
  150.                 if (TOGGLE_ON_CLICK) {
  151.                     mSystemUiHider.toggle();
  152.                 } else {
  153.                     mSystemUiHider.show();
  154.                 }
  155.             }
  156.         });
  157.  
  158.         // Upon interacting with UI controls, delay any scheduled hide()
  159.         // operations to prevent the jarring behavior of controls going away
  160.         // while interacting with the UI.
  161.         findViewById(R.id.dummy_button).setOnTouchListener(
  162.                 mDelayHideTouchListener);
  163.        
  164.         Button button = (Button) findViewById(R.id.dummy_button);
  165.         button.setOnClickListener(new View.OnClickListener() {
  166.             public void onClick(View v) {
  167.                 Intent i = new Intent();
  168.                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  169.                     i.setAction(Intent.ACTION_OPEN_DOCUMENT);
  170.                 } else {
  171.                     i.setAction(Intent.ACTION_GET_CONTENT);
  172.                 }
  173.                 i.addCategory(Intent.CATEGORY_OPENABLE);
  174.                 i.setType("image/*");
  175.                 startActivityForResult(i, 1);
  176.             }
  177.         });
  178.        
  179.     }
  180.  
  181.     @Override
  182.     protected void onPostCreate(Bundle savedInstanceState) {
  183.         super.onPostCreate(savedInstanceState);
  184.  
  185.         // Trigger the initial hide() shortly after the activity has been
  186.         // created, to briefly hint to the user that UI controls
  187.         // are available.
  188.         delayedHide(100);
  189.     }
  190.  
  191.     /**
  192.      * Touch listener to use for in-layout UI controls to delay hiding the
  193.      * system UI. This is to prevent the jarring behavior of controls going away
  194.      * while interacting with activity UI.
  195.      */
  196.     View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
  197.         @Override
  198.         public boolean onTouch(View view, MotionEvent motionEvent) {
  199.             if (AUTO_HIDE) {
  200.                 delayedHide(AUTO_HIDE_DELAY_MILLIS);
  201.             }
  202.             return false;
  203.         }
  204.     };
  205.  
  206.     Handler mHideHandler = new Handler();
  207.     Runnable mHideRunnable = new Runnable() {
  208.         @Override
  209.         public void run() {
  210.             mSystemUiHider.hide();
  211.         }
  212.     };
  213.  
  214.     /**
  215.      * Schedules a call to hide() in [delay] milliseconds, canceling any
  216.      * previously scheduled calls.
  217.      */
  218.     private void delayedHide(int delayMillis) {
  219.         mHideHandler.removeCallbacks(mHideRunnable);
  220.         mHideHandler.postDelayed(mHideRunnable, delayMillis);
  221.     }
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement