Example usage for android.os Handler postDelayed

List of usage examples for android.os Handler postDelayed

Introduction

In this page you can find the example usage for android.os Handler postDelayed.

Prototype

public final boolean postDelayed(Runnable r, long delayMillis) 

Source Link

Document

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.

Usage

From source file:edu.pitt.gis.uniapp.UniApp.java

/**
 * Shows the splash screen over the full Activity
 *//*from w ww .ja  va2  s . c  o  m*/
@SuppressWarnings("deprecation")
protected void showSplashScreen(final int time) {
    final UniApp that = this;

    Runnable runnable = new Runnable() {
        public void run() {
            // Get reference to display
            Display display = getWindowManager().getDefaultDisplay();

            // Create the layout for the dialog
            LinearLayout root = new LinearLayout(that.getActivity());
            root.setMinimumHeight(display.getHeight());
            root.setMinimumWidth(display.getWidth());
            root.setOrientation(LinearLayout.VERTICAL);
            root.setBackgroundColor(that.getIntegerProperty("backgroundColor", Color.BLACK));
            root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.FILL_PARENT, 0.0F));
            root.setBackgroundResource(that.splashscreen);

            // Create and show the dialog
            splashDialog = new Dialog(that, android.R.style.Theme_Translucent_NoTitleBar);
            // check to see if the splash screen should be full screen
            if ((getWindow().getAttributes().flags
                    & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) {
                splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
            splashDialog.setContentView(root);
            splashDialog.setCancelable(false);
            splashDialog.show();

            // Set Runnable to remove splash screen just in case
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    removeSplashScreen();
                }
            }, time);
        }
    };
    this.runOnUiThread(runnable);
}

From source file:com.snt.bt.recon.activities.MainActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(com.snt.bt.recon.R.layout.activity_main);
    ButterKnife.bind(this);
    logDebug("Activity", "######################## On Create ########################");
    //Lock orientation
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    //Leave screen on
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    //leave cpu on
    wl = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "wlTag");
    wl.acquire();/*  w  ww.  ja  v a  2 s.c o  m*/

    //For device id
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    //for connectivity
    cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    try {

        logDebug("DatabaseTest", "Reading all trips..");
        List<Trip> trips = db.getAll(Trip.class);
        for (Trip trip : trips) {
            String log = "session id: " + trip.getSessionId() + " imei: " + trip.getImei() + " transport: "
                    + trip.getTransport() + " TS: " + trip.getTimestampStart() + " TE: "
                    + trip.getTimestampEnd() + " upload status: " + trip.getUploadStatus();
            logDebug("DatabaseTest", log);
        }
        logDebug("DatabaseTest", "Reading all locations..");
        List<GPSLocation> locs = db.getAll(GPSLocation.class);
        for (GPSLocation loc : locs) {
            String log = "loc id: " + loc.getLocationId() + " sess id: " + loc.getSessionId() + " timestamp: "
                    + loc.getTimestamp() + " upload status: " + loc.getUploadStatus();
            logDebug("DatabaseTest", log);
        }
        logDebug("DatabaseTest", "Reading all bc..");
        List<BluetoothClassicEntry> bcs = db.getAll(BluetoothClassicEntry.class);
        for (BluetoothClassicEntry bc : bcs) {
            String log = "sess id: " + bc.getSessionId() + " loc id: " + bc.getLocationId() + " upload status: "
                    + bc.getUploadStatus();
            logDebug("DatabaseTest", log);
        }
        logDebug("DatabaseTest", "Reading all ble..");
        List<BluetoothLowEnergyEntry> bles = db.getAll(BluetoothLowEnergyEntry.class);
        for (BluetoothLowEnergyEntry ble : bles) {
            String log = "sess id: " + ble.getSessionId() + " loc id: " + ble.getLocationId()
                    + " upload status: " + ble.getUploadStatus();
            logDebug("DatabaseTest", log);
        }
    } catch (InstantiationException | IllegalAccessException e) {
        e.printStackTrace();
    }

    //Show select transpot mode
    new TransportMode(this).show();

    // Show EULA
    new AppEULA(this).show();

    //displayFeedbackDialog();

    //avtivity recognition start
    mActivityRecognitionScan = new ActivityRecognitionUtil(this);
    mActivityRecognitionScan.startActivityRecognitionScan();
    //Filter the Intent and register broadcast receiver
    registerReceiver(ActivityRecognitionReceiver, new IntentFilter("ImActive"));

    //gps
    gpsStatusCheck();

    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    locationListener = new MyLocationListener();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 3, locationListener);

    //bt
    mBluetoothUtils = new BluetoothUtils(this);

    //ble
    mLeDeviceStore = new BluetoothLeDeviceStore();
    mLeScanner = new BluetoothLeScanner(mLeScanCallback, mBluetoothUtils);
    //bc
    mBcDeviceList = new ArrayList<>();

    final Handler h = new Handler();
    final int delay = 60000;

    h.postDelayed(new Runnable() {
        public void run() {
            syncServerDatabase();

            h.postDelayed(this, delay);
        }
    }, delay);

    //Clean BLE table in case device last timestamp is > 10 seconds
    final Handler h2 = new Handler();
    h2.postDelayed(new Runnable() {
        public void run() {
            //clear old ble devices
            for (BluetoothLeDevice device : mLeDeviceStore.getDeviceList()) {
                long diff = System.currentTimeMillis() - device.getTimestamp();
                if (diff > 10000) {
                    mLeDeviceStore.removeDevice(device);
                    //Refresh the listview
                    final EasyObjectCursor<BluetoothLeDevice> c = mLeDeviceStore.getDeviceCursor();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mLeDeviceListAdapter.swapCursor(c);
                        }
                    });
                }
            }

            h2.postDelayed(this, 1000);//1 sec
        }
    }, 1000);
}

From source file:com.alibaba.android.layoutmanager.example.OnePlusNLayoutActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    mFirstText = (TextView) findViewById(R.id.first);
    mLastText = (TextView) findViewById(R.id.last);
    mCountText = (TextView) findViewById(R.id.count);
    mTotalOffsetText = (TextView) findViewById(R.id.total_offset);

    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);

    findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() {
        @Override// w  ww. j  a  v a2s.  c o m
        public void onClick(View v) {
            EditText position = (EditText) findViewById(R.id.position);
            if (!TextUtils.isEmpty(position.getText())) {
                try {
                    int pos = Integer.parseInt(position.getText().toString());
                    recyclerView.scrollToPosition(pos);
                } catch (Exception e) {
                    Log.e("VlayoutActivity", e.getMessage(), e);
                }
            } else {
                recyclerView.requestLayout();
            }
        }
    });

    final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);

    recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {

        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int i, int i2) {
            mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition());
            mLastText.setText(
                    "Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes);
            mCountText.setText("Count: " + recyclerView.getChildCount());
            mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart());
        }
    });

    recyclerView.setLayoutManager(layoutManager);

    // layoutManager.setReverseLayout(true);

    RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() {
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            int position = ((LayoutParams) view.getLayoutParams()).getViewPosition();
            outRect.set(4, 4, 4, 4);
        }
    };

    final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();

    recyclerView.setRecycledViewPool(viewPool);

    // recyclerView.addItemDecoration(itemDecoration);

    viewPool.setMaxRecycledViews(0, 20);

    final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true);

    recyclerView.setAdapter(delegateAdapter);

    List<DelegateAdapter.Adapter> adapters = new LinkedList<>();

    if (BANNER_LAYOUT) {
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) {

            @Override
            public void onViewRecycled(MainViewHolder holder) {
                if (holder.itemView instanceof ViewPager) {
                    ((ViewPager) holder.itemView).setAdapter(null);
                }
            }

            @Override
            public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                if (viewType == 1)
                    return new MainViewHolder(LayoutInflater.from(OnePlusNLayoutActivity.this)
                            .inflate(R.layout.view_pager, parent, false));

                return super.onCreateViewHolder(parent, viewType);
            }

            @Override
            public int getItemViewType(int position) {
                return 1;
            }

            @Override
            protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {

            }

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                if (holder.itemView instanceof ViewPager) {
                    ViewPager viewPager = (ViewPager) holder.itemView;

                    viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200));

                    // from position to get adapter
                    viewPager.setAdapter(new PagerAdapter(this, viewPool));
                }
            }
        });
    }

    if (GRID_LAYOUT) {
        GridLayoutHelper layoutHelper;
        layoutHelper = new GridLayoutHelper(4);
        layoutHelper.setMargin(0, 10, 0, 10);
        layoutHelper.setHGap(3);
        layoutHelper.setAspectRatio(4f);
        adapters.add(new SubAdapter(this, layoutHelper, 8));
    }

    if (HORIZONTAL_SCROLL_LAYOUT) {

    }

    if (GRID_LAYOUT) {
        GridLayoutHelper layoutHelper;
        layoutHelper = new GridLayoutHelper(2);
        layoutHelper.setMargin(0, 10, 0, 10);
        layoutHelper.setHGap(3);
        layoutHelper.setAspectRatio(3f);
        adapters.add(new SubAdapter(this, layoutHelper, 2));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(10, 10, 10, 10);
        helper.setPadding(10, 10, 10, 10);
        adapters.add(new SubAdapter(this, helper, 3) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                //                    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
                //                    layoutParams.leftMargin = 10;
                //                    layoutParams.topMargin = 10;
                //                    layoutParams.rightMargin = 10;
                //                    layoutParams.bottomMargin = 10;
                //                    holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 4));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 5));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 5));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f });
        adapters.add(new SubAdapter(this, helper, 5));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 20f, 80f, 0f, 60f, 20f });
        helper.setAspectRatio(4);
        adapters.add(new SubAdapter(this, helper, 5));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 6));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 7));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f, 30f, 30f });
        adapters.add(new SubAdapter(this, helper, 7));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xffed7612);
        //            helper.setMargin(10, 10, 10, 10);
        //            helper.setPadding(10, 10, 10, 10);
        helper.setColWeights(new float[] { 30f, 20f, 50f, 40f, 30f, 35f, 35f });
        adapters.add(new SubAdapter(this, helper, 7) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                //                    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
                //                    layoutParams.leftMargin = 10;
                //                    layoutParams.topMargin = 10;
                //                    layoutParams.rightMargin = 10;
                //                    layoutParams.bottomMargin = 10;
                //                    holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }

    if (STICKY_LAYOUT) {
        StickyLayoutHelper layoutHelper = new StickyLayoutHelper();
        layoutHelper.setAspectRatio(4);
        adapters.add(new SubAdapter(this, layoutHelper, 1,
                new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
    }

    if (SCROLL_FIX_LAYOUT) {
        ScrollFixLayoutHelper layoutHelper = new ScrollFixLayoutHelper(FixLayoutHelper.BOTTOM_RIGHT, 20, 20);
        layoutHelper.setShowType(ScrollFixLayoutHelper.SHOW_ON_LEAVE);
        adapters.add(new SubAdapter(this, layoutHelper, 1) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LayoutParams layoutParams = new LayoutParams(50, 50);
                holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }

    if (LINEAR_LAYOUT)
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 100));

    delegateAdapter.setAdapters(adapters);

    final Handler mainHandler = new Handler(Looper.getMainLooper());

    trigger = new Runnable() {
        @Override
        public void run() {
            // recyclerView.scrollToPosition(22);
            // recyclerView.getAdapter().notifyDataSetChanged();
            recyclerView.requestLayout();
            // mainHandler.postDelayed(trigger, 1000);
        }
    };

    mainHandler.postDelayed(trigger, 1000);
}

From source file:mgks.os.webview.MainActivity.java

@SuppressLint({ "SetJavaScriptEnabled", "WrongViewCast" })
@Override/*  ww w . ja va2s .co  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.w("READ_PERM = ", Manifest.permission.READ_EXTERNAL_STORAGE);
    Log.w("WRITE_PERM = ", Manifest.permission.WRITE_EXTERNAL_STORAGE);
    //Prevent the app from being started again when it is still alive in the background
    if (!isTaskRoot()) {
        finish();
        return;
    }

    setContentView(R.layout.activity_main);

    asw_view = findViewById(R.id.msw_view);

    final SwipeRefreshLayout pullfresh = findViewById(R.id.pullfresh);
    if (ASWP_PULLFRESH) {
        pullfresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                pull_fresh();
                pullfresh.setRefreshing(false);
            }
        });
        asw_view.getViewTreeObserver()
                .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                    @Override
                    public void onScrollChanged() {
                        if (asw_view.getScrollY() == 0) {
                            pullfresh.setEnabled(true);
                        } else {
                            pullfresh.setEnabled(false);
                        }
                    }
                });
    } else {
        pullfresh.setRefreshing(false);
        pullfresh.setEnabled(false);
    }

    if (ASWP_PBAR) {
        asw_progress = findViewById(R.id.msw_progress);
    } else {
        findViewById(R.id.msw_progress).setVisibility(View.GONE);
    }
    asw_loading_text = findViewById(R.id.msw_loading_text);
    Handler handler = new Handler();

    //Launching app rating request
    if (ASWP_RATINGS) {
        handler.postDelayed(new Runnable() {
            public void run() {
                get_rating();
            }
        }, 1000 * 60); //running request after few moments
    }

    //Getting basic device information
    get_info();

    //Getting GPS location of device if given permission
    if (ASWP_LOCATION && !check_permission(1)) {
        ActivityCompat.requestPermissions(MainActivity.this,
                new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, loc_perm);
    }
    get_location();

    //Webview settings; defaults are customized for best performance
    WebSettings webSettings = asw_view.getSettings();

    if (!ASWP_OFFLINE) {
        webSettings.setJavaScriptEnabled(ASWP_JSCRIPT);
    }
    webSettings.setSaveFormData(ASWP_SFORM);
    webSettings.setSupportZoom(ASWP_ZOOM);
    webSettings.setGeolocationEnabled(ASWP_LOCATION);
    webSettings.setAllowFileAccess(true);
    webSettings.setAllowFileAccessFromFileURLs(true);
    webSettings.setAllowUniversalAccessFromFileURLs(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setDomStorageEnabled(true);

    asw_view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            return true;
        }
    });
    asw_view.setHapticFeedbackEnabled(false);

    asw_view.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType,
                long contentLength) {

            if (!check_permission(2)) {
                ActivityCompat.requestPermissions(MainActivity.this, new String[] {
                        Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE },
                        file_perm);
            } else {
                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));

                request.setMimeType(mimeType);
                String cookies = CookieManager.getInstance().getCookie(url);
                request.addRequestHeader("cookie", cookies);
                request.addRequestHeader("User-Agent", userAgent);
                request.setDescription(getString(R.string.dl_downloading));
                request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
                        URLUtil.guessFileName(url, contentDisposition, mimeType));
                DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                assert dm != null;
                dm.enqueue(request);
                Toast.makeText(getApplicationContext(), getString(R.string.dl_downloading2), Toast.LENGTH_LONG)
                        .show();
            }
        }
    });

    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));
        asw_view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    } else if (Build.VERSION.SDK_INT >= 19) {
        asw_view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    asw_view.setVerticalScrollBarEnabled(false);
    asw_view.setWebViewClient(new Callback());

    //Rendering the default URL
    aswm_view(ASWV_URL, false);

    asw_view.setWebChromeClient(new WebChromeClient() {
        //Handling input[type="file"] requests for android API 16+
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            if (ASWP_FUPLOAD) {
                asw_file_message = uploadMsg;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType(ASWV_F_TYPE);
                if (ASWP_MULFILE) {
                    i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                }
                startActivityForResult(Intent.createChooser(i, getString(R.string.fl_chooser)), asw_file_req);
            }
        }

        //Handling input[type="file"] requests for android API 21+
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                FileChooserParams fileChooserParams) {
            if (check_permission(2) && check_permission(3)) {
                if (ASWP_FUPLOAD) {
                    if (asw_file_path != null) {
                        asw_file_path.onReceiveValue(null);
                    }
                    asw_file_path = filePathCallback;
                    Intent takePictureIntent = null;
                    if (ASWP_CAMUPLOAD) {
                        takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) {
                            File photoFile = null;
                            try {
                                photoFile = create_image();
                                takePictureIntent.putExtra("PhotoPath", asw_cam_message);
                            } catch (IOException ex) {
                                Log.e(TAG, "Image file creation failed", ex);
                            }
                            if (photoFile != null) {
                                asw_cam_message = "file:" + photoFile.getAbsolutePath();
                                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                            } else {
                                takePictureIntent = null;
                            }
                        }
                    }
                    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
                    if (!ASWP_ONLYCAM) {
                        contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
                        contentSelectionIntent.setType(ASWV_F_TYPE);
                        if (ASWP_MULFILE) {
                            contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                        }
                    }
                    Intent[] intentArray;
                    if (takePictureIntent != null) {
                        intentArray = new Intent[] { takePictureIntent };
                    } else {
                        intentArray = new Intent[0];
                    }

                    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
                    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
                    chooserIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.fl_chooser));
                    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
                    startActivityForResult(chooserIntent, asw_file_req);
                }
                return true;
            } else {
                get_file();
                return false;
            }
        }

        //Getting webview rendering progress
        @Override
        public void onProgressChanged(WebView view, int p) {
            if (ASWP_PBAR) {
                asw_progress.setProgress(p);
                if (p == 100) {
                    asw_progress.setProgress(0);
                }
            }
        }

        // overload the geoLocations permissions prompt to always allow instantly as app permission was granted previously
        public void onGeolocationPermissionsShowPrompt(String origin,
                GeolocationPermissions.Callback callback) {
            if (Build.VERSION.SDK_INT < 23 || check_permission(1)) {
                // location permissions were granted previously so auto-approve
                callback.invoke(origin, true, false);
            } else {
                // location permissions not granted so request them
                ActivityCompat.requestPermissions(MainActivity.this,
                        new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, loc_perm);
            }
        }
    });
    if (getIntent().getData() != null) {
        String path = getIntent().getDataString();
        /*
        If you want to check or use specific directories or schemes or hosts
                
        Uri data        = getIntent().getData();
        String scheme   = data.getScheme();
        String host     = data.getHost();
        List<String> pr = data.getPathSegments();
        String param1   = pr.get(0);
        */
        aswm_view(path, false);
    }
}

From source file:com.example.rx.ui.OnePlusNLayoutActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity2);

    mFirstText = (TextView) findViewById(R.id.first);
    mLastText = (TextView) findViewById(R.id.last);
    mCountText = (TextView) findViewById(R.id.count);
    mTotalOffsetText = (TextView) findViewById(R.id.total_offset);

    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);

    findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() {
        @Override//from w w w  .  j a  v  a  2s  . c  o  m
        public void onClick(View v) {
            EditText position = (EditText) findViewById(R.id.position);
            if (!TextUtils.isEmpty(position.getText())) {
                try {
                    int pos = Integer.parseInt(position.getText().toString());
                    recyclerView.scrollToPosition(pos);
                } catch (Exception e) {
                    Log.e("VlayoutActivity", e.getMessage(), e);
                }
            } else {
                recyclerView.requestLayout();
            }
        }
    });

    final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);

    recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {

        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int i, int i2) {
            mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition());
            mLastText.setText(
                    "Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes);
            mCountText.setText("Count: " + recyclerView.getChildCount());
            mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart());
        }
    });

    recyclerView.setLayoutManager(layoutManager);

    // layoutManager.setReverseLayout(true);

    RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() {
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            int position = ((LayoutParams) view.getLayoutParams()).getViewPosition();
            outRect.set(4, 4, 4, 4);
        }
    };

    final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();

    recyclerView.setRecycledViewPool(viewPool);

    // recyclerView.addItemDecoration(itemDecoration);

    viewPool.setMaxRecycledViews(0, 20);

    final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true);

    recyclerView.setAdapter(delegateAdapter);

    List<DelegateAdapter.Adapter> adapters = new LinkedList<>();

    if (BANNER_LAYOUT) {
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) {

            @Override
            public void onViewRecycled(MainViewHolder holder) {
                if (holder.itemView instanceof ViewPager) {
                    ((ViewPager) holder.itemView).setAdapter(null);
                }
            }

            @Override
            public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                if (viewType == 1)
                    return new MainViewHolder(LayoutInflater.from(OnePlusNLayoutActivity.this)
                            .inflate(R.layout.view_pager, parent, false));

                return super.onCreateViewHolder(parent, viewType);
            }

            @Override
            public int getItemViewType(int position) {
                return 1;
            }

            @Override
            protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {

            }

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                if (holder.itemView instanceof ViewPager) {
                    ViewPager viewPager = (ViewPager) holder.itemView;

                    viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200));

                    // from position to get adapter
                    viewPager.setAdapter(new PagerAdapter(this, viewPool));
                }
            }
        });
    }

    if (GRID_LAYOUT) {
        GridLayoutHelper layoutHelper;
        layoutHelper = new GridLayoutHelper(4);
        layoutHelper.setMargin(0, 10, 0, 10);
        layoutHelper.setHGap(3);
        layoutHelper.setAspectRatio(4f);
        adapters.add(new SubAdapter(this, layoutHelper, 8));
    }

    if (HORIZONTAL_SCROLL_LAYOUT) {

    }

    if (GRID_LAYOUT) {
        GridLayoutHelper layoutHelper;
        layoutHelper = new GridLayoutHelper(2);
        layoutHelper.setMargin(0, 10, 0, 10);
        layoutHelper.setHGap(3);
        layoutHelper.setAspectRatio(3f);
        adapters.add(new SubAdapter(this, layoutHelper, 2));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(10, 10, 10, 10);
        helper.setPadding(10, 10, 10, 10);
        adapters.add(new SubAdapter(this, helper, 3) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                //                    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
                //                    layoutParams.leftMargin = 10;
                //                    layoutParams.topMargin = 10;
                //                    layoutParams.rightMargin = 10;
                //                    layoutParams.bottomMargin = 10;
                //                    holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 4));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 5));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 5));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f });
        adapters.add(new SubAdapter(this, helper, 5));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 20f, 80f, 0f, 60f, 20f });
        helper.setAspectRatio(4);
        adapters.add(new SubAdapter(this, helper, 5));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 6));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 7));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f, 30f, 30f });
        adapters.add(new SubAdapter(this, helper, 7));
    }

    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xffed7612);
        //            helper.setMargin(10, 10, 10, 10);
        //            helper.setPadding(10, 10, 10, 10);
        helper.setColWeights(new float[] { 30f, 20f, 50f, 40f, 30f, 35f, 35f });
        adapters.add(new SubAdapter(this, helper, 7) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                //                    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
                //                    layoutParams.leftMargin = 10;
                //                    layoutParams.topMargin = 10;
                //                    layoutParams.rightMargin = 10;
                //                    layoutParams.bottomMargin = 10;
                //                    holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }

    if (STICKY_LAYOUT) {
        StickyLayoutHelper layoutHelper = new StickyLayoutHelper();
        layoutHelper.setAspectRatio(4);
        adapters.add(new SubAdapter(this, layoutHelper, 1,
                new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
    }

    if (SCROLL_FIX_LAYOUT) {
        ScrollFixLayoutHelper layoutHelper = new ScrollFixLayoutHelper(FixLayoutHelper.BOTTOM_RIGHT, 20, 20);
        layoutHelper.setShowType(ScrollFixLayoutHelper.SHOW_ON_LEAVE);
        adapters.add(new SubAdapter(this, layoutHelper, 1) {
            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LayoutParams layoutParams = new LayoutParams(50, 50);
                holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }

    if (LINEAR_LAYOUT)
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 100));

    delegateAdapter.setAdapters(adapters);

    final Handler mainHandler = new Handler(Looper.getMainLooper());

    trigger = new Runnable() {
        @Override
        public void run() {
            // recyclerView.scrollToPosition(22);
            // recyclerView.getAdapter().notifyDataSetChanged();
            recyclerView.requestLayout();
            // mainHandler.postDelayed(trigger, 1000);
        }
    };

    mainHandler.postDelayed(trigger, 1000);
}

From source file:syncthing.android.ui.LauncherActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Timber.d("onActivityResult(%d, %d, %s)", requestCode, resultCode, data);
    final Handler handler = new Handler();
    switch (requestCode) {
    case ActivityRequestCodes.LOGIN_ACTIVITY:
    case ActivityRequestCodes.MANAGE_ACTIVITY:
    case ActivityRequestCodes.WELCOME_ACTIVITY: {
        // OK with credentials opens the device
        if (resultCode == Activity.RESULT_OK && data != null
                && data.hasExtra(ManageActivity.EXTRA_CREDENTIALS)) {
            Timber.d("Got Positive response");
            data.setExtrasClassLoader(LauncherActivity.class.getClassLoader());
            final Credentials currentDevice = data.getParcelableExtra(ManageActivity.EXTRA_CREDENTIALS);
            if (currentDevice != null) {
                Timber.d("Found credentials in the intent");
                handler.postDelayed(() -> populateNavigationMenu(currentDevice, true), 10);
                return;
            }/*www.j  a  v  a2  s.c o  m*/
        }
        Timber.d("Result either canceled or missing credentials");
        //IDK just open the drawer
        handler.postDelayed(() -> {
            populateNavigationMenu(null, false);
            openDrawer(GravityCompat.START);
        }, 10);
        break;
    }
    default:
        Timber.d("Unknown request code");
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
}

From source file:cn.fantasee.swipwmenulistview.swipelistview.SwipeListViewTouchListener.java

/**
 * Will call {@link #removePendingDismisses(int)} in animationTime + 100 ms.
 * @param originalHeight will be used to rest the cells height.
 *///from   w  w  w. j a va 2 s  .c  om
protected void handlerPendingDismisses(final int originalHeight) {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            removePendingDismisses(originalHeight);
        }
    }, animationTime + 100);
}

From source file:com.theOldMen.listener.SwipeListViewTouchListener.java

/**
 * Will call {@link #removePendingDismisses(int)} in animationTime + 100 ms.
 * @param originalHeight will be used to rest the cells height.
 *///from  ww  w.ja  va 2s.co  m
public void handlerPendingDismisses(final int originalHeight) {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            removePendingDismisses(originalHeight);
        }
    }, animationTime + 100);
}

From source file:com.javielinux.fragments.MyActivityFragment.java

public void deleteUser() {
    if (idUser > 0) {
        Entity ent = new Entity("users", idUser);

        String sqlTweetsDelete = "DELETE FROM tweets_user WHERE user_tt_id=" + ent.getId();
        DataFramework.getInstance().getDB().execSQL(sqlTweetsDelete);

        String sqlColumnsDelete = "DELETE FROM columns WHERE user_id=" + ent.getId();
        DataFramework.getInstance().getDB().execSQL(sqlColumnsDelete);

        ent.delete();//from   w  ww .j  a  v a 2 s  .c  o  m

        fillData();

        Handler myHandler = new Handler();
        myHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                ((TweetTopicsActivity) getActivity()).getFragmentPagerAdapter().refreshColumnList();
                ((TweetTopicsActivity) getActivity()).refreshActionBarColumns();
            }
        }, 100);
    }
}

From source file:com.campusclipper.android.MyLocationActivity.java

@Override
public boolean onMarkerClick(final Marker marker) {
    if (marker.equals(mPerth)) {
        // This causes the marker at Perth to bounce into position when it is clicked.
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override/*from w w w .ja v  a 2 s . c  om*/
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
                marker.setAnchor(0.5f, 1.0f + 2 * t);

                if (t > 0.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    } else if (marker.equals(mAdelaide)) {
        // This causes the marker at Adelaide to change color and alpha.
        marker.setIcon(BitmapDescriptorFactory.defaultMarker(mRandom.nextFloat() * 360));
        marker.setAlpha(mRandom.nextFloat());
    }
    // We return false to indicate that we have not consumed the event and that we wish
    // for the default behavior to occur (which is for the camera to move such that the
    // marker is centered and for the marker's info window to open, if it has one).
    return false;
}