Example usage for android.app Activity getResources

List of usage examples for android.app Activity getResources

Introduction

In this page you can find the example usage for android.app Activity getResources.

Prototype

@Override
    public Resources getResources() 

Source Link

Usage

From source file:kr.wdream.storyshop.AndroidUtilities.java

public static void lockOrientation(Activity activity) {
    if (activity == null || prevOrientation != -10) {
        return;//from  ww w .j a v  a 2  s .co m
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_90) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_0) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            } else {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:com.popofibo.weatherpop.custom.ActionBarDrawerToggle.java

/**
 * Construct a new ActionBarDrawerToggle.
 * /*  www.  j a  v a  2  s  .c o  m*/
 * <p>
 * The given {@link Activity} will be linked to the specified
 * {@link DrawerLayout}. The provided drawer indicator drawable will animate
 * slightly off-screen as the drawer is opened, indicating that in the open
 * state the drawer will move off-screen when pressed and in the closed
 * state the drawer will move on-screen when pressed.
 * </p>
 * 
 * <p>
 * String resources must be provided to describe the open/close drawer
 * actions for accessibility services.
 * </p>
 * 
 * @param activity
 *            The Activity hosting the drawer
 * @param drawerLayout
 *            The DrawerLayout to link to the given Activity's ActionBar
 * @param drawerImageRes
 *            A Drawable resource to use as the drawer indicator
 * @param openDrawerContentDescRes
 *            A String resource to describe the "open drawer" action for
 *            accessibility
 * @param closeDrawerContentDescRes
 *            A String resource to describe the "close drawer" action for
 *            accessibility
 */
public ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, int drawerImageRes,
        int openDrawerContentDescRes, int closeDrawerContentDescRes) {
    mActivity = activity;
    mDrawerLayout = drawerLayout;
    mDrawerImageResource = drawerImageRes;
    mOpenDrawerContentDescRes = openDrawerContentDescRes;
    mCloseDrawerContentDescRes = closeDrawerContentDescRes;

    mThemeImage = getThemeUpIndicator();
    mDrawerImage = activity.getResources().getDrawable(drawerImageRes);
    mSlider = new SlideDrawable(mDrawerImage);
    mSlider.setOffsetBy(1.f / 3);

    // Allow the Activity to provide an impl
    if (activity instanceof DelegateProvider) {
        mActivityImpl = ((DelegateProvider) activity).getDrawerToggleDelegate();
    } else {
        mActivityImpl = null;
    }
}

From source file:org.chromium.chrome.browser.download.ui.DownloadManagerUi.java

public DownloadManagerUi(Activity activity, boolean isOffTheRecord, ComponentName parentComponent) {
    mActivity = activity;/*from w  w  w .  ja  va2  s.com*/
    mBackendProvider = sProviderForTests == null ? new DownloadBackendProvider() : sProviderForTests;

    mMainView = (ViewGroup) LayoutInflater.from(activity).inflate(R.layout.download_main, null);

    mEmptyView = (TextView) mMainView.findViewById(R.id.empty_view);
    mEmptyView.setCompoundDrawablesWithIntrinsicBounds(null,
            VectorDrawableCompat.create(activity.getResources(), R.drawable.downloads_big, activity.getTheme()),
            null, null);
    mLoadingView = (LoadingView) mMainView.findViewById(R.id.loading_view);
    mLoadingView.showLoadingUI();

    mHistoryAdapter = new DownloadHistoryAdapter(isOffTheRecord, parentComponent);
    mHistoryAdapter.registerAdapterDataObserver(mAdapterObserver);
    mHistoryAdapter.initialize(mBackendProvider);
    addObserver(mHistoryAdapter);

    mSpaceDisplay = new SpaceDisplay(mMainView, mHistoryAdapter);
    mHistoryAdapter.registerAdapterDataObserver(mSpaceDisplay);
    mSpaceDisplay.onChanged();

    mFilterAdapter = new FilterAdapter();
    mFilterAdapter.initialize(this);
    addObserver(mFilterAdapter);

    mToolbar = (DownloadManagerToolbar) mMainView.findViewById(R.id.action_bar);
    mToolbar.setOnMenuItemClickListener(this);
    DrawerLayout drawerLayout = null;
    if (!DeviceFormFactor.isLargeTablet(activity)) {
        drawerLayout = (DrawerLayout) mMainView;
        addDrawerListener(drawerLayout);
    }
    mToolbar.initialize(mBackendProvider.getSelectionDelegate(), 0, drawerLayout, R.id.normal_menu_group,
            R.id.selection_mode_menu_group);
    addObserver(mToolbar);

    mFilterView = (ListView) mMainView.findViewById(R.id.section_list);
    mFilterView.setAdapter(mFilterAdapter);
    mFilterView.setOnItemClickListener(mFilterAdapter);

    mRecyclerView = (RecyclerView) mMainView.findViewById(R.id.recycler_view);
    mRecyclerView.setAdapter(mHistoryAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(activity));

    FadingShadowView shadow = (FadingShadowView) mMainView.findViewById(R.id.shadow);
    if (DeviceFormFactor.isLargeTablet(mActivity)) {
        shadow.setVisibility(View.GONE);
    } else {
        shadow.init(ApiCompatibilityUtils.getColor(mMainView.getResources(), R.color.toolbar_shadow_color),
                FadingShadow.POSITION_TOP);
    }

    mToolbar.setTitle(R.string.menu_downloads);

    mUndoDeletionSnackbarController = new UndoDeletionSnackbarController();
}

From source file:com.nikola.despotoski.drawerlayoutedgetoggle.DrawerLayoutEdgeToggle.java

public DrawerLayoutEdgeToggle(Activity a, DrawerLayout l, int drawerOpen, int drawerClose,
        boolean keepShadowOnHandle, int drawerGravity) {

    if (drawerGravity != GravityCompat.END && drawerGravity != GravityCompat.START
            && drawerGravity != Gravity.LEFT && drawerGravity != Gravity.RIGHT)
        throw new IllegalArgumentException(
                "Use: GravityCompat.END, GravityCompat.START, Gravity.LEFT or Gravity.RIGHT for drawerGravity parameter");
    mGravity = drawerGravity;//from   w w  w  . j av  a 2  s. co m
    mActivity = a;
    mDrawerLayout = l;
    mOpenDrawable = a.getResources().getDrawable(drawerOpen);
    mCloseDrawable = a.getResources().getDrawable(drawerClose);
    rootLayout = (FrameLayout) mActivity.findViewById(android.R.id.content);
    mHandle = new ImageView(a);
    final ViewTreeObserver viewTreeObserver = mHandle.getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            @SuppressLint("NewApi")
            @Override
            public void onGlobalLayout() {
                mDrawerLayout.measure(MeasureSpec.EXACTLY, MeasureSpec.EXACTLY);
                syncState();
                removeOnGlobalLayoutListener(mHandle, this);
            }
        });
    }

    mHandle.setOnClickListener(mHandleClickListenerInt);
    mHandle.setOnTouchListener(mHandleTouchListenerInt);
    mHandle.setSaveEnabled(true);
    mDrawerLayout.setOnTouchListener(mHandleTouchListenerInt);
    rootLayout.addView(mHandle,
            new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, drawerGravity));
    mKeepShadowOnHandle = keepShadowOnHandle;
    mCurrentDrawable = mCloseDrawable;
}

From source file:io.plaidapp.ui.FeedAdapter.java

public FeedAdapter(Activity hostActivity, DataLoadingSubject dataLoading, int columns,
        boolean pocketInstalled) {
    this.host = hostActivity;
    this.dataLoading = dataLoading;
    this.columns = columns;
    this.pocketIsInstalled = pocketInstalled;
    layoutInflater = LayoutInflater.from(host);
    comparator = new PlaidItemComparator();
    items = new ArrayList<>();
    setHasStableIds(true);//  w w  w. j  a  v  a  2 s .c o m
    TypedArray placeholderColors = hostActivity.getResources().obtainTypedArray(R.array.loading_placeholders);
    shotLoadingPlaceholders = new ColorDrawable[placeholderColors.length()];
    for (int i = 0; i < placeholderColors.length(); i++) {
        shotLoadingPlaceholders[i] = new ColorDrawable(placeholderColors.getColor(i, Color.DKGRAY));
    }
}

From source file:com.chromium.fontinstaller.util.ViewUtils.java

public static void reveal(Activity activity, View view, View sourceView, int colorRes) {
    if (activity == null || view == null || sourceView == null)
        return;/*from   w w w .ja v  a 2s  . com*/
    if (isLollipop()) {
        final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) activity.getWindow().getDecorView()
                .getOverlay();

        final Rect displayRect = new Rect();
        view.getGlobalVisibleRect(displayRect);

        // Make reveal cover the display and status bar.
        final View revealView = new View(activity);
        revealView.setTop(displayRect.top);
        revealView.setBottom(displayRect.bottom);
        revealView.setLeft(displayRect.left);
        revealView.setRight(displayRect.right);
        revealView.setBackgroundColor(ContextCompat.getColor(activity, colorRes));
        groupOverlay.add(revealView);

        final int[] clearLocation = new int[2];
        sourceView.getLocationInWindow(clearLocation);
        clearLocation[0] += sourceView.getWidth() / 2;
        clearLocation[1] += sourceView.getHeight() / 2;

        final int revealCenterX = clearLocation[0] - revealView.getLeft();
        final int revealCenterY = clearLocation[1] - revealView.getTop();

        final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
        final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
        final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
        final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

        try {
            final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
                    revealCenterY, 0.0f, revealRadius);
            revealAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_mediumAnimTime));

            final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
            alphaAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_shortAnimTime));
            alphaAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.abc_fade_in));
                    view.setVisibility(View.VISIBLE);
                }
            });

            final AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.play(revealAnimator).before(alphaAnimator);
            animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
            animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animator) {
                    groupOverlay.remove(revealView);
                }
            });

            animatorSet.start();
        } catch (IllegalStateException e) {
            Timber.i("View is detached - not animating");
        }
    } else {
        view.setVisibility(View.VISIBLE);
    }
}

From source file:com.todoroo.astrid.actfm.EditPeopleControlSet.java

public EditPeopleControlSet(Activity activity, Fragment fragment, int viewLayout, int displayViewLayout,
        int title, int loginRequestCode) {
    super(activity, viewLayout, displayViewLayout, title);
    DependencyInjectionService.getInstance().inject(this);
    this.resources = activity.getResources();
    this.loginRequestCode = loginRequestCode;
    this.fragment = fragment;

    assignedCustom = (EditText) getView().findViewById(R.id.assigned_custom);
    assignedList = (ListView) getView().findViewById(R.id.assigned_list);
    assignedList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    assignedList.setItemsCanFocus(false);
    assignedClear = getView().findViewById(R.id.assigned_clear);

    assignedDisplay = (TextView) getDisplayView().findViewById(R.id.display_row_edit);
    image = (ImageView) getDisplayView().findViewById(R.id.display_row_icon);
    setUpListeners();//  w ww . j  a va2  s.  com
}

From source file:org.jorge.lolin1.func.custom.navdrawerfix.FixedActionBarDrawerToggle.java

/**
 * Construct a new ActionBarDrawerToggle.
 * <p/>//from w w w.  j  a v a2  s. com
 * <p>The given {@link Activity} will be linked to the specified {@link org.jorge.lolin1.func.custom.navdrawerfix.FixedDrawerLayout}.
 * The provided drawer indicator drawable will animate slightly off-screen as the drawer
 * is opened, indicating that in the open state the drawer will move off-screen when pressed
 * and in the closed state the drawer will move on-screen when pressed.</p>
 * <p/>
 * <p>String resources must be provided to describe the open/close drawer actions for
 * accessibility services.</p>
 *
 * @param activity                  The Activity hosting the drawer
 * @param drawerLayout              The DrawerLayout to link to the given Activity's ActionBar
 * @param drawerImageRes            A Drawable resource to use as the drawer indicator
 * @param openDrawerContentDescRes  A String resource to describe the "open drawer" action
 *                                  for accessibility
 * @param closeDrawerContentDescRes A String resource to describe the "close drawer" action
 *                                  for accessibility
 */
public FixedActionBarDrawerToggle(Activity activity, FixedDrawerLayout drawerLayout, int drawerImageRes,
        int openDrawerContentDescRes, int closeDrawerContentDescRes) {
    mActivity = activity;

    // Allow the Activity to provide an impl
    if (activity instanceof DelegateProvider) {
        mActivityImpl = ((DelegateProvider) activity).getDrawerToggleDelegate();
    } else {
        mActivityImpl = null;
    }

    mDrawerLayout = drawerLayout;
    mDrawerImageResource = drawerImageRes;
    mOpenDrawerContentDescRes = openDrawerContentDescRes;
    mCloseDrawerContentDescRes = closeDrawerContentDescRes;

    mThemeImage = getThemeUpIndicator();
    mDrawerImage = activity.getResources().getDrawable(drawerImageRes);
    mSlider = new SlideDrawable(mDrawerImage);
    mSlider.setOffset(TOGGLE_DRAWABLE_OFFSET);
}

From source file:com.suarez.cordova.mapsforge.MapsforgePlugin.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if ("global-status".equals(action)) {
        this.status();
        callbackContext.success();//from  w w  w .  j  av a 2 s.co m
        return true;
    } else if (action.contains("native-")) {
        if ("native-set-center".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.setCenter(args.getDouble(0), args.getDouble(1));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-zoom".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.setZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.show();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }
            return true;
        } else if ("native-hide".equals(action)) {
            MapsforgeNative.INSTANCE.hide();
            return true;
        } else if ("native-marker".equals(action)) {
            try {
                Activity context = this.cordova.getActivity();

                int markerId = context.getResources().getIdentifier(args.getString(0), "drawable",
                        context.getPackageName());
                if (markerId == 0) {
                    Log.i(MapsforgePlugin.TAG, "Marker not found...using default marker: marker_green");
                    markerId = context.getResources().getIdentifier("marker_green", "drawable",
                            context.getPackageName());
                }

                int markerKey = MapsforgeNative.INSTANCE.addMarker(markerId, args.getDouble(1),
                        args.getDouble(2));
                callbackContext.success(markerKey);
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-polyline".equals(action)) {

            try {
                JSONArray points = args.getJSONArray(2);

                if (points.length() % 2 != 0)
                    throw new JSONException("Invalid array of coordinates. Length should be multiple of 2");

                int polylineKey = MapsforgeNative.INSTANCE.addPolyline(args.getInt(0), args.getInt(1), points);

                callbackContext.success(polylineKey);
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-delete-layer".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.deleteLayer(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-initialize".equals(action)) {

            try {

                MapsforgeNative.createInstance(this.cordova.getActivity(), args.getString(0), args.getInt(1),
                        args.getInt(2));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-max-zoom".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMaxZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-set-min-zoom".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMinZoom(Byte.parseByte(args.getString(0)));
                callbackContext.success();
            } catch (NumberFormatException nfe) {
                callbackContext.error("Incorrect argument format. Should be: (byte zoom)");
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show-controls".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setBuiltInZoomControls(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-clickable".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setClickable(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-show-scale".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.showScaleBar(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-destroy-cache".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.destroyCache(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            }

            return true;
        } else if ("native-map-path".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setMapFilePath(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException iae) {
                callbackContext.error(iae.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-cache-name".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setCacheName(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-theme-path".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setRenderThemePath(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-stop".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onStop();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-start".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onStart();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-destroy".equals(action)) {
            try {
                MapsforgeNative.INSTANCE.onDestroy();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-online".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setOnline(args.getString(0), args.getString(1), args.getString(2),
                        args.getString(3), args.getInt(4));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("native-offline".equals(action)) {

            try {
                MapsforgeNative.INSTANCE.setOffline(args.getString(0), args.getString(1));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        }
    } else if (action.contains("cache-")) {
        if ("cache-get-tile".equals(action)) {

            try {
                final long x = args.getLong(0);
                final long y = args.getLong(1);
                final byte z = Byte.parseByte(args.getString(2));
                final CallbackContext callbacks = callbackContext;

                cordova.getThreadPool().execute(new Runnable() {
                    public void run() {
                        try {
                            String path = MapsforgeCache.INSTANCE.getTilePath(x, y, z);
                            callbacks.success(path);
                        } catch (IOException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-initialize".equals(action)) {

            try {
                MapsforgeCache.createInstance(cordova.getActivity(), args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (IllegalArgumentException e) {
                callbackContext.error(e.getMessage());
            } catch (IOException e) {
                callbackContext.error(e.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-map-path".equals(action)) {

            try {
                final String mapFile = args.getString(0);
                final CallbackContext callbacks = callbackContext;

                cordova.getThreadPool().execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            MapsforgeCache.INSTANCE.setMapFilePath(mapFile);
                            callbacks.success();
                        } catch (IllegalArgumentException e) {
                            callbacks.error(e.getMessage());
                        } catch (FileNotFoundException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-max-size".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setMaxCacheSize(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-max-age".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setMaxCacheAge(args.getLong(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-cleaning-trigger".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCleanCacheTrigger(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-enabled".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCacheEnabled(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-external".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setExternalCache(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-name".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCacheName(args.getString(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-tile-size".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setTileSize(args.getInt(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-clean-destroy".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setCleanOnDestroy(args.getBoolean(0));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-theme-path".equals(action)) {

            try {
                final CallbackContext callbacks = callbackContext;
                final String themePath = args.getString(0);

                cordova.getThreadPool().execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            MapsforgeCache.INSTANCE.setRenderTheme(themePath);
                            callbacks.success();
                        } catch (IllegalArgumentException e) {
                            callbacks.error(e.getMessage());
                        } catch (FileNotFoundException e) {
                            callbacks.error(e.getMessage());
                        } catch (Exception e) {
                            callbacks.error(e.getMessage());
                        }
                    }
                });
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-screen-ratio".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setScreenRatio(Float.parseFloat(args.getString(0)));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-overdraw".equals(action)) {

            try {
                MapsforgeCache.INSTANCE.setOverdrawFactor(Float.parseFloat(args.getString(0)));
                callbackContext.success();
            } catch (JSONException je) {
                callbackContext.error(je.getMessage());
            } catch (NumberFormatException nfe) {
                callbackContext.error(nfe.getMessage());
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        } else if ("cache-destroy".equals(action)) {
            try {
                MapsforgeCache.INSTANCE.onDestroy();
                callbackContext.success();
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }

            return true;
        }
    }
    return false; // Returning false results in a "MethodNotFound" error.
}

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

public static void lockOrientation(Activity activity) {
    if (activity == null || prevOrientation != -10) {
        return;//www.  j  av  a2s .c o m
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_90) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_0) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            } else {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}