Example usage for android.content.res Resources getIdentifier

List of usage examples for android.content.res Resources getIdentifier

Introduction

In this page you can find the example usage for android.content.res Resources getIdentifier.

Prototype

public int getIdentifier(String name, String defType, String defPackage) 

Source Link

Document

Return a resource identifier for the given resource name.

Usage

From source file:com.sonymobile.android.media.testmediaplayer.MainActivity.java

public void init() {
    if (mMediaPlayer == null) {
        mMediaPlayer = new MediaPlayer(getApplicationContext());
        mMediaPlayer.setScreenOnWhilePlaying(true);
    }/*from  w  w w .  ja  v a2 s  .  c o m*/
    mHandler = new Handler();
    mDecorView = getWindow().getDecorView();
    mSeekbar = (SeekBar) findViewById(R.id.activity_main_seekbar);
    mSeekbar.setMax(1000);
    mPlayPauseButton = (ImageView) findViewById(R.id.activity_main_playpause_button);
    mSeekBarUpdater = new SeekbarUpdater(mSeekbar, mMediaPlayer);
    mTopLayout = (RelativeLayout) findViewById(R.id.activity_main_mainlayout);
    mTrackDialog = new AudioSubtitleTrackDialog(this);
    mAudioPos = mSubPos = 0;
    mTimeView = (TextView) findViewById(R.id.activity_main_time);
    mDurationView = (TextView) findViewById(R.id.activity_main_duration);
    mTimeLayout = (LinearLayout) findViewById(R.id.activity_main_timelayout);
    mTimeTracker = new TimeTracker(mMediaPlayer, mTimeView);
    mSubtitleView = (TextView) findViewById(R.id.activity_main_subtitleView);
    mSubtitleRenderer = new SubtitleRenderer(mSubtitleView, Looper.myLooper(), mMediaPlayer);
    mSubtitleLayoutAboveTimeView = (RelativeLayout.LayoutParams) mSubtitleView.getLayoutParams();
    mSubtitleLayoutBottom = (RelativeLayout.LayoutParams) ((TextView) findViewById(
            R.id.activity_main_subtitleView_params)).getLayoutParams();
    mTimeSeekView = (TextView) findViewById(R.id.activity_main_time_seek);
    mMediaPlayer.setOnInfoListener(this);
    RelativeLayout browsingL = (RelativeLayout) findViewById(R.id.activity_main_browsing_layout);
    ExpandableListView elv = (ExpandableListView) browsingL.findViewById(R.id.file_browsing_exp_list_view);
    ListView lv = (ListView) browsingL.findViewById(R.id.file_browsing_listview);
    RelativeLayout debugLayout = (RelativeLayout) findViewById(R.id.activity_main_debug_view);
    LinearLayout debugLinearLayout = (LinearLayout) debugLayout.findViewById(R.id.activity_main_debug_linear);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setScrimColor(Color.TRANSPARENT);
    mDrawerLayout.setDrawerListener(this);
    mFileBrowser = new MediaBrowser(this, elv, lv, mMediaPlayer, (MainActivity) this, mDrawerLayout,
            debugLinearLayout);
    mIsFileBrowsing = false;
    mPreview = (SurfaceView) findViewById(R.id.mSurfaceView);
    mPreview.setOnTouchListener(this);
    mTopLayout.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    mPreview.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    mSubtitleTracker = new HashMap<Integer, Integer>();
    mAudioTracker = new HashMap<Integer, Integer>();
    findViewById(R.id.activity_main_loading_panel).bringToFront();
    findViewById(R.id.activity_main_browsing_layout).bringToFront();
    mUpperControls = (RelativeLayout) findViewById(R.id.UpperButtonLayout);
    mBottomControls = (RelativeLayout) findViewById(R.id.ButtonLayout);
    mSlideInAnimation = AnimationUtils.loadAnimation(this, R.anim.in_top);
    mSlideInAnimation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationEnd(Animation animation) {
            mUpperControls.setVisibility(View.VISIBLE);
            Runnable r = new Runnable() {
                @Override
                public void run() {
                    mBottomControls.setVisibility(View.INVISIBLE);
                }
            };
            mHandler.postDelayed(r, 3500);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationStart(Animation animation) {
            mBottomControls.setVisibility(View.INVISIBLE);
        }
    });
    mHolder = mPreview.getHolder();
    mHolder.addCallback(this);
    mFadeOutRunnable = new Runnable() {
        @Override
        public void run() {
            mSeekbar.setEnabled(false);
            Animation fadeoutBottom = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.out_bottom);
            fadeoutBottom.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationEnd(Animation animation) {
                    if (mOngoingAnimation) {
                        mOngoingAnimation = false;
                        mBottomControls.setVisibility(View.INVISIBLE);
                        mUpperControls.setVisibility(View.INVISIBLE);
                        mSeekbar.setVisibility(View.GONE);
                        mTimeLayout.setVisibility(View.GONE);
                        mSubtitleView.setLayoutParams(mSubtitleLayoutBottom);
                    }
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationStart(Animation animation) {
                    mOngoingAnimation = true;
                }
            });
            Animation fadeoutTop = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.out_top);
            mBottomControls.startAnimation(fadeoutBottom);
            mUpperControls.startAnimation(fadeoutTop);
            mSeekbar.startAnimation(fadeoutBottom);
            mTimeLayout.startAnimation(fadeoutBottom);
        }
    };
    mHideNavigationRunnable = new Runnable() {
        @Override
        public void run() {
            mPreview.setSystemUiVisibility(mUiOptions);
        }
    };

    mDecorView.setOnSystemUiVisibilityChangeListener(this);
    mSeekbar.setOnSeekBarChangeListener(new OwnOnSeekBarChangeListener(mMediaPlayer));
    mMediaPlayer.setOnCompletionListener(this);
    mMediaPlayer.setOnPreparedListener(this);
    mMediaPlayer.setOnSeekCompleteListener(this);
    mMediaPlayer.setOnErrorListener(this);
    mMediaPlayer.setOnSubtitleDataListener(this);

    RelativeLayout browsingLayout = (RelativeLayout) findViewById(R.id.activity_main_browsing_layout);
    DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) browsingLayout.getLayoutParams();
    Resources resources = getResources();
    int top = 0;
    int bottom = 0;
    RelativeLayout.LayoutParams tempParams;
    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        top = resources.getDimensionPixelSize(resourceId);
    }
    resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        bottom = resources.getDimensionPixelSize(resourceId);
    }
    if (navigationBarAtBottom()) {
        tempParams = (RelativeLayout.LayoutParams) mBottomControls.getLayoutParams();
        tempParams.bottomMargin += bottom;
        mBottomControls.setLayoutParams(tempParams);
        tempParams = (RelativeLayout.LayoutParams) mSeekbar.getLayoutParams();
        tempParams.bottomMargin += bottom;
        mSeekbar.setLayoutParams(tempParams);
        params.setMargins(0, top, 0, bottom);
    } else {
        tempParams = (RelativeLayout.LayoutParams) mBottomControls.getLayoutParams();
        tempParams.rightMargin += bottom;
        mBottomControls.setLayoutParams(tempParams);
        params.setMargins(0, top, 0, 0);
    }
    browsingLayout.setLayoutParams(params);
    mDrawerLayout.openDrawer(Gravity.START);

    mMediaPlayer.setOnOutputControlListener(this);
}

From source file:com.likemag.cordova.inappbrowsercustom.InAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject//from w  w w .  j av a  2 s  . c  o m
 */
public String showWebPage(final String url, HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setInAppBroswer(getInAppBrowser());

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            //Please, no more black! 
            toolbar.setBackgroundColor(android.graphics.Color.WHITE);
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            Resources activityRes = cordova.getActivity().getResources();
            int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable backIcon = activityRes.getDrawable(backResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                back.setBackgroundDrawable(backIcon);
            } else {
                back.setBackground(backIcon);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable fwdIcon = activityRes.getDrawable(fwdResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                forward.setBackgroundDrawable(fwdIcon);
            } else {
                forward.setBackground(fwdIcon);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close/Done button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setText(getPostName());
            close.setTextSize(20.0f);
            close.setTextColor(android.graphics.Color.GRAY);
            close.setId(5);
            int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable closeIcon = activityRes.getDrawable(backResId);
            closeIcon.setBounds(0, 0, 40, 40);
            close.setPadding(0, 0, 0, 0);
            close.setBackgroundDrawable(null);
            close.setCompoundDrawables(closeIcon, null, null, null);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                //close.setBackgroundDrawable(closeIcon);
            } else {
                //close.setBackground(closeIcon);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true
                    : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            //toolbar.addView(actionButtonContainer);
            //toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.mobiroller.tools.inappbrowser.MobirollerInAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject/*  w w w. ja v  a2s  .c  o m*/
 */
public String showWebPage(final String url, final HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    showZoomControls = false;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean zoom = features.get(ZOOM);
        if (zoom != null) {
            showZoomControls = zoom.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
        if (hardwareBack != null) {
            hadwareBackButton = hardwareBack.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new MobirollerInAppBrowserDialog(cordova.getActivity(),
                    android.R.style.Theme_Translucent_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setInAppBroswer(getInAppBrowser());

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setBackgroundColor(Color.TRANSPARENT);
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            //Please, no more black!
            toolbar.setBackgroundColor(Color.TRANSPARENT);
            toolbar.setLayoutParams(new RelativeLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
                    this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            Resources activityRes = cordova.getActivity().getResources();
            int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable backIcon = activityRes.getDrawable(backResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                back.setBackgroundDrawable(backIcon);
            } else {
                back.setBackground(backIcon);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable fwdIcon = activityRes.getDrawable(fwdResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                forward.setBackgroundDrawable(fwdIcon);
            } else {
                forward.setBackground(fwdIcon);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close/Done button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable closeIcon = activityRes.getDrawable(closeResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                close.setBackgroundDrawable(closeIcon);
            } else {
                close.setBackground(closeIcon);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new MobirollerInAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(showZoomControls);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true
                    : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            //                toolbar.addView(actionButtonContainer);
            //                toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            //Mobiroller Needs
            DisplayMetrics metrics = cordova.getActivity().getResources().getDisplayMetrics();
            Rect windowRect = new Rect();
            webView.getView().getWindowVisibleDisplayFrame(windowRect);

            int bottomGap = 0;
            if (features.containsKey("hasTabs")) {
                if (features.get("hasTabs")) {
                    bottomGap += Math.ceil(44 * metrics.density);
                }
            }
            lp.height = (windowRect.bottom - windowRect.top) - (bottomGap);
            lp.gravity = Gravity.TOP;
            lp.format = PixelFormat.TRANSPARENT;
            close.setAlpha(0);
            //Mobiroller Needs

            dialog.setContentView(main);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.show();
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.phonegap.bossbolo.plugin.inappbrowser.InAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject// w w  w  . j  a v a 2 s  .  c o m
 * @param header
 */
public String showWebPage(final String url, HashMap<String, Boolean> features, final String header) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    showZoomControls = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean zoom = features.get(ZOOM);
        if (zoom != null) {
            showZoomControls = zoom.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
        if (hardwareBack != null) {
            hadwareBackButton = hardwareBack.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        @SuppressLint("NewApi")
        public void run() {
            int backgroundColor = Color.parseColor("#46bff7");
            // Let's create the main dialog
            dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setInAppBroswer(getInAppBrowser());

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout  header
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            //Please, no more black! 
            toolbar.setBackgroundColor(android.graphics.Color.LTGRAY);
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(50)));
            toolbar.setPadding(this.dpToPixels(8), this.dpToPixels(10), this.dpToPixels(8),
                    this.dpToPixels(10));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);
            toolbar.setBackgroundColor(backgroundColor);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            back.setWidth(this.dpToPixels(34));
            back.setHeight(this.dpToPixels(31));
            Resources activityRes = cordova.getActivity().getResources();
            int backResId = activityRes.getIdentifier("back", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable backIcon = activityRes.getDrawable(backResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                back.setBackgroundDrawable(backIcon);
            } else {
                back.setBackground(backIcon);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                    //                        goBack();
                }
            });

            // Edit Text Box
            titletext = new TextView(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, this.dpToPixels(65));
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, this.dpToPixels(10));
            titletext.setLayoutParams(textLayoutParams);
            titletext.setId(3);
            titletext.setSingleLine(true);
            titletext.setText(header);
            titletext.setTextColor(Color.WHITE);
            titletext.setGravity(Gravity.CENTER);
            titletext.setTextSize(TypedValue.COMPLEX_UNIT_PX, this.dpToPixels(20));
            titletext.setSingleLine();
            titletext.setEllipsize(TruncateAt.END);

            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams editLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            editLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            editLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setVisibility(View.GONE);

            // Forward button
            /*Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName());
            Drawable fwdIcon = activityRes.getDrawable(fwdResId);
            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            {
            forward.setBackgroundDrawable(fwdIcon);
            }
            else
            {
            forward.setBackground(fwdIcon);
            }
            forward.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                goForward();
            }
            });
                    
            // Edit Text Box
            edittext = new TextView(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  navigate(edittext.getText().toString());
                  return true;
                }
                return false;
            }
            });
                    
                    
            // Close/Done button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
            Drawable closeIcon = activityRes.getDrawable(closeResId);
            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            {
            close.setBackgroundDrawable(closeIcon);
            }
            else
            {
            close.setBackground(closeIcon);
            }
            close.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                closeDialog();
            }
            });*/

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(getShowZoomControls());
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true
                    : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            //                actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(titletext);
            //                toolbar.addView(edittext);
            //                toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.pk.wallpapermanager.PkWallpaperManager.java

/**
 * Loads wallpapers stored locally.<br>
 * Make sure to have set your String Array of Local Wallpapers in 
 * your settings before calling this method.
 *//*from  ww  w.  j  a v  a2s .c om*/
public void fetchLocalWallpapers() {
    final String[] localWallpapers = mSettings.getLocalWallpapers();
    final String packageName = mSettings.getPackageName();
    final String thumbSuffix = mSettings.getThumbSuffix();

    if (debugEnabled)
        Log.d(LOG_TAG, "Loading local wallpapers...");

    // Basic resources
    Resources resources = mContext.getResources();
    mLocalWallpapers.clear();
    Wallpaper mWall = null;

    // Loop through all listeners notifying them
    for (LocalWallpaperListener mListener : mLocalWallpaperListeners) {
        mListener.onLocalWallpapersLoading();
    }

    // Loop through extras looking for local wallpapers.
    for (String localWallpaper : localWallpapers) {
        int res = resources.getIdentifier(localWallpaper, "drawable", packageName);

        if (res != 0) {
            final int thumbRes = resources.getIdentifier(localWallpaper + thumbSuffix, "drawable", packageName);
            mWall = new Wallpaper();

            mWall.setFullResource(res);
            mWall.setFullUri(Uri.parse(RESOURCE_URI_BASE + packageName + "/drawable/" + localWallpaper));
            mWall.setThumbResource(thumbRes);
            mWall.setThumbUri(
                    Uri.parse(RESOURCE_URI_BASE + packageName + "/drawable/" + localWallpaper + thumbSuffix));
            mWall.setLocal(true);

            mLocalWallpapers.add(mWall);
            mWall = null;
        }
    }

    if (debugEnabled)
        Log.d(LOG_TAG, "Finished loading " + mLocalWallpapers.size() + " local wallpapers!");

    // Loop through all listeners notifying them
    for (LocalWallpaperListener mListener : mLocalWallpaperListeners) {
        mListener.onLocalWallpapersLoaded();
    }
}

From source file:com.yerdy.services.Yerdy.java

/**
 * Initializes Yerdy//from   ww w .j  a  v a 2 s.co  m
 * 
 * @param context   current activity context
 * @param publisherKey   Your publisher key (get one from <a href="http://www.yerdy.com">here</a>)
 * @category Configuration
 */
public void startWithPublisherKey(Context context, String publisherKey) {
    _initialized = true;
    Resources res = context.getResources();
    int icon = res.getIdentifier("notification_icon", "drawable", Yerdy.getInstance().getAppPackage());
    YRDPushManager.Register(context, icon);

    _publisherKey = publisherKey.substring(0, 16);
    _publisherSecret = publisherKey.substring(16);
    _appPacakge = context.getPackageName();
    _appVersionName = "0.0.1";
    _appVersionCode = 0;
    if (_currencyTracker == null)
        _currencyTracker = new YRDCurrencyTracker(context.getApplicationContext());
    if (_historyTracker == null)
        _historyTracker = new YRDHistoryTracker(context.getApplicationContext());
    if (_progressionTracker == null)
        _progressionTracker = new YRDProgressionTracker(context.getApplicationContext(), _historyTracker);
    if (_eventTracker == null)
        _eventTracker = new YRDEventTracker(context.getApplicationContext());
    if (_adRequestTracker == null)
        _adRequestTracker = new YRDAdRequestTracker(context.getApplicationContext());
    if (_featureMasteryTracker == null)
        _featureMasteryTracker = new YRDFeatureMasteryTracker(context, _historyTracker);

    try {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(_appPacakge, 0);
        _appVersionName = packageInfo.versionName;
        _appVersionCode = packageInfo.versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    _applicationContext = context.getApplicationContext();
    _installerPackage = context.getPackageManager().getInstallerPackageName(_appPacakge);
    YRDAnalytics.getInstance().setLaunchClient(context, new YRDLaunchClient() {
        @Override
        public void launchReported() {
            fetchMessages(_applicationContext);
        }

        @Override
        public void launchReportFailed(Exception error) {
            fetchMessages(_applicationContext);
        }

        @Override
        public void launchSkipped() {
            if (_forceMessageFetchNextResume)
                fetchMessages(_applicationContext);
        }
    });

    boolean newVersion = YRDAnalytics.getInstance().versionMismatch();
    if (newVersion)
        _adRequestTracker.newVersionDetected();

    YRDAnalytics.getInstance().appHandleActivate(context, _currencyTracker.generateCurrencyReport(null),
            _adRequestTracker.generateReport(), _historyTracker, false);
    queueTimeMilestone();
    _adRequestTracker.didReportToServer();

    YRDLog.i(this.getClass(), "Starting.  Version: " + YerdyVersion.VERSION);
    YRDLog.i(this.getClass(),
            "To enable test mode for this device, copy/paste the device ID below into the Yerdy dashboard.");
    YRDLog.i(this.getClass(), "Device ID: " + YerdyUtil.getUDID(context));
}

From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MainActivity mainActivity = (MainActivity) getActivity();
    if (mainActivity == null)
        return;//w  w  w  .j  a v a2  s.co  m
    CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout) mainActivity
            .findViewById(R.id.toolbar_layout);
    toolbarLayout.setTitle(getString(R.string.app_name));

    if (((DrawerLayout) mainActivity.drawer) // drawer is locked
            .getDrawerLockMode(mainActivity.drawerView) == DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
        return;

    inflater.inflate(lyrics, menu);
    // Get the SearchView and set the searchable configuration
    final MaterialSuggestionsSearchView materialSearchView = (MaterialSuggestionsSearchView) mainActivity
            .findViewById(R.id.material_search_view);
    materialSearchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(final String query) {
            materialSearchView.setSuggestions(null);
            materialSearchView.requestFocus();
            materialSearchView.post(new Runnable() {
                @Override
                public void run() {
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(materialSearchView.getWindowToken(), 0);
                }
            });
            materialSearchView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    ((MainActivity) getActivity()).search(query);
                    materialSearchView.setSuggestions(null);
                }
            }, 90);
            mExpandedSearchView = false;
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!materialSearchView.hasSuggestions())
                materialSearchView.setSuggestions(materialSearchView.getHistory());
            return true;
        }
    });

    materialSearchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
        @Override
        public void onSearchViewShown() {
            if (getActivity() == null)
                return;
            ((ControllableAppBarLayout) getActivity().findViewById(R.id.appbar)).expandToolbar(true);
            mExpandedSearchView = true;
        }

        @Override
        public void onSearchViewClosed() {
            mExpandedSearchView = false;
        }
    });

    final Resources resources = getResources();
    final int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    int statusBarHeight;
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP)
        statusBarHeight = 0;
    else if (resourceId > 0)
        statusBarHeight = resources.getDimensionPixelSize(resourceId);
    else
        statusBarHeight = (int) Math.ceil((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? 24 : 25)
                * resources.getDisplayMetrics().density);
    CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) materialSearchView.getLayoutParams();
    lp.setMargins(lp.leftMargin, statusBarHeight, lp.rightMargin, lp.bottomMargin);
    materialSearchView.setLayoutParams(lp);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    materialSearchView.setMenuItem(searchItem);

    if (!materialSearchView.isSearchOpen() && mExpandedSearchView) {
        materialSearchView.showSearch();
        mExpandedSearchView = false;
    } else if (!mExpandedSearchView)
        materialSearchView.closeSearch();

    materialSearchView.setHint(getString(R.string.search_hint));
    if (mSearchQuery != null && !mSearchQuery.equals("")) {
        searchItem.expandActionView();
        materialSearchView.setQuery(mSearchQuery, false);
        if (mSearchFocused)
            materialSearchView.requestFocus();
        else
            materialSearchView.clearFocus();
        mSearchQuery = null;
    }
    Lyrics storedLyrics = mLyrics == null ? null
            : DatabaseHelper.getInstance(getActivity()).get(new String[] { mLyrics.getArtist(),
                    mLyrics.getTitle(), mLyrics.getOriginalArtist(), mLyrics.getOriginalTrack() });

    MenuItem saveMenuItem = menu.findItem(R.id.save_action);
    if (saveMenuItem != null) {
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
        if (mLyrics == null)
            saveMenuItem.setVisible(false);
        else if (mLyrics.getFlag() == Lyrics.POSITIVE_RESULT && sharedPref.getBoolean("pref_auto_save", true)) {
            if (storedLyrics == null || (mLyrics.isLRC() && !storedLyrics.isLRC())) {
                lyricsPresentInDB = true;
                new WriteToDatabaseTask().execute(this, saveMenuItem, mLyrics);
            }
            saveMenuItem.setVisible(false);
        } else {
            saveMenuItem.setIcon(lyricsPresentInDB ? R.drawable.ic_trash : R.drawable.ic_save);
            saveMenuItem.setTitle(lyricsPresentInDB ? R.string.remove_action : R.string.save_action);
        }
    }
    MenuItem resyncMenuItem = menu.findItem(R.id.resync_action);
    MenuItem convertMenuItem = menu.findItem(R.id.convert_action);
    if (resyncMenuItem != null)
        resyncMenuItem.setVisible(mLyrics != null && mLyrics.isLRC());
    if (convertMenuItem != null) {
        Lyrics stored = mLyrics == null || mLyrics.isLRC() ? null : storedLyrics;
        convertMenuItem
                .setVisible((mLyrics != null && (mLyrics.isLRC())) || (stored != null && stored.isLRC()));
        convertMenuItem.setTitle(stored == null ? R.string.full_text_action : R.string.pref_lrc);
    }

    MenuItem shareMenuItem = menu.findItem(R.id.share_action);
    if (shareMenuItem != null)
        shareMenuItem.setVisible(
                mLyrics != null && mLyrics.getFlag() == Lyrics.POSITIVE_RESULT && mLyrics.getURL() != null);
}

From source file:com.android.launcher3.Utilities.java

/**
 * Returns a bitmap suitable for the all apps view. If the package or the resource do not
 * exist, it returns null.//from  w  ww  .j av  a 2 s. c o m
 */
public static Bitmap createIconBitmap(String packageName, String resourceName, Context context) {
    PackageManager packageManager = context.getPackageManager();
    // the resource
    try {
        Resources resources = packageManager.getResourcesForApplication(packageName);
        if (resources != null) {
            final int id = resources.getIdentifier(resourceName, null, null);
            return createIconBitmap(
                    resources.getDrawableForDensity(id,
                            LauncherAppState.getInstance().getInvariantDeviceProfile().fillResIconDpi),
                    context);
        }
    } catch (Exception e) {
        // Icon not found.
    }
    return null;
}

From source file:com.svpino.longhorn.fragments.StockListFragment.java

private Intent getDefaultShareIntent(Integer position) {
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");

    Stock stock = null;/*w  w  w. j av a2s  .com*/
    if (position == null) {
        if (isOverviewVisible() && this.viewFlipper != null && this.viewFlipper.getTag() != null) {
            stock = this.callback.getStockList().get((Integer) this.viewFlipper.getTag());
        }
    } else {
        stock = this.callback.getStockList().get(position);
    }

    if (stock != null) {
        Resources resources = getActivity().getResources();
        intent.putExtra("symbol", stock.getSymbol());
        intent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                String.format(resources.getString(R.string.fragment_stock_overview_share_subject),
                        stock.getSymbol(), stock.getStringPrice()));

        int resourceIdentifier = resources.getIdentifier(
                "fragment_stock_overview_share_message_" + Constants.STORE, "string",
                getActivity().getPackageName());

        intent.putExtra(android.content.Intent.EXTRA_TEXT,
                String.format(resources.getString(resourceIdentifier), stock.getSymbol(),
                        stock.getStringPrice(), stock.getStringChangeAndChangePercentage(),
                        resources.getString(R.string.application_name)));
    }

    return intent;
}

From source file:com.miz.functions.MizLib.java

public static int getNavigationBarWidth(Context context) {
    Resources resources = context.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_width", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }// www . ja va  2  s. c  om
    return 0;
}