Example usage for android.view Gravity CENTER

List of usage examples for android.view Gravity CENTER

Introduction

In this page you can find the example usage for android.view Gravity CENTER.

Prototype

int CENTER

To view the source code for android.view Gravity CENTER.

Click Source Link

Document

Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.

Usage

From source file:com.devwang.logcabin.LogCabinMainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent serverIntent = null;/*from ww  w  . j a v  a  2s  . c  o m*/
    Toast toast = Toast.makeText(LogCabinMainActivity.this, "", Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    switch (item.getItemId()) {
    case R.id.secure_connect_scan:// 
        // Launch the DeviceListActivity to see devices and do scan
        serverIntent = new Intent(this, DeviceListActivity.class);
        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE);
        return true;
    case R.id.insecure_connect_scan:// 
        // Launch the DeviceListActivity to see devices and do scan
        serverIntent = new Intent(this, DeviceListActivity.class);
        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_INSECURE);
        return true;
    case R.id.app_developer:
        toastDisplay(LogCabinMainActivity.this,
                ":   \n\nQQ:1120341494\n:dongleixiaxue314\n :http://www.devwang.com",
                Gravity.CENTER, R.drawable.hutview, Toast.LENGTH_SHORT);
        return true;
    case R.id.app_cmd_what:
    case R.id.app_voice_what:
        toast.setText(
                "\n\n\n\n...");
        toast.show();
        return true;
    case R.id.app_college:
        toast.setText(R.string.str_college);
        toast.show();
        return true;
    case R.id.app_web_url:
        toastDisplay(LogCabinMainActivity.this,
                getString(R.string.http_devwang_sinaapp_com_logcabin_logcabin_web_php), Gravity.CENTER, 0,
                Toast.LENGTH_SHORT);
        return true;
    case R.id.app_update:

        android.app.AlertDialog.Builder dialog = new AlertDialog.Builder(LogCabinMainActivity.this);
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dialogview_appupdate, null);
        dialog.setView(layout);
        appUpdateEditText = (EditText) layout.findViewById(R.id.et_appupdate);
        dialog.setPositiveButton(R.string.str_app_update_sure, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                String appUpdateEditTextString = appUpdateEditText.getText().toString();
                if ("devwang".equals(appUpdateEditTextString.toString())) {
                    AppUpdate = true;
                    Toast.makeText(getApplicationContext(), R.string.str_app_update_pass_toast,
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
        dialog.show();
        return true;
    }
    return false;
}

From source file:com.sam_chordas.android.stockhawk.ui.MyStocksActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

    setContentView(R.layout.activity_my_stocks);
    // The intent service is for executing immediate pulls from the Yahoo API
    // GCMTaskService can only schedule tasks, they cannot execute immediately
    mServiceIntent = new Intent(this, StockIntentService.class);
    if (savedInstanceState == null) {
        // Run the initialize task service so that some stocks appear upon an empty database
        mServiceIntent.putExtra("tag", "init");
        if (Utils.isNetworkAvailable(mContext)) {
            startService(mServiceIntent);
        } else {/*from  w w w  .j  ava2s  .  c  o  m*/
            networkToast();
        }
    }
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    getLoaderManager().initLoader(CURSOR_LOADER_ID, null, this);

    mCursorAdapter = new QuoteCursorAdapter(this, null);
    recyclerView.addOnItemTouchListener(
            new RecyclerViewItemClickListener(this, new RecyclerViewItemClickListener.OnItemClickListener() {
                @Override
                public void onItemClick(View v, int position) {
                    // CursorAdapter returns a cursor at the correct position for getItem(), or null
                    // if it cannot seek to that position.
                    Intent intent = new Intent(getApplicationContext(), LineGraphActivity.class);
                    intent.putExtra(STOCK_ITEM, mCursorAdapter.getItemSymbol(position));
                    startActivity(intent);
                }
            }));
    recyclerView.setAdapter(mCursorAdapter);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.attachToRecyclerView(recyclerView);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Utils.isNetworkAvailable(mContext)) {
                new MaterialDialog.Builder(mContext).title(R.string.symbol_search)
                        .content(R.string.content_test).inputType(InputType.TYPE_CLASS_TEXT)
                        .input(R.string.input_hint, R.string.input_prefill, new MaterialDialog.InputCallback() {
                            @Override
                            public void onInput(MaterialDialog dialog, CharSequence input) {
                                // On FAB click, receive user input. Make sure the stock doesn't already exist
                                // in the DB and proceed accordingly
                                Cursor c = getContentResolver().query(QuoteProvider.Quotes.CONTENT_URI,
                                        new String[] { QuoteColumns.SYMBOL }, QuoteColumns.SYMBOL + "= ?",
                                        new String[] { input.toString() }, null);
                                if (c.getCount() != 0) {
                                    Toast toast = Toast.makeText(MyStocksActivity.this,
                                            "This stock is already saved!", Toast.LENGTH_LONG);
                                    toast.setGravity(Gravity.CENTER, Gravity.CENTER, 0);
                                    toast.show();
                                    return;
                                } else {
                                    // Add the stock to DB
                                    mServiceIntent.putExtra("tag", "add");
                                    mServiceIntent.putExtra("symbol", input.toString());
                                    startService(mServiceIntent);

                                }
                            }
                        }).show();
            } else {
                networkToast();
            }

        }
    });

    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mCursorAdapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(recyclerView);

    mTitle = getTitle();
    if (Utils.isNetworkAvailable(mContext)) {
        long period = 30L;
        long flex = 10L;
        String periodicTag = "periodic";

        // create a periodic task to pull stocks once every hour after the app has been opened. This
        // is so Widget data stays up to date.
        PeriodicTask periodicTask = new PeriodicTask.Builder().setService(StockTaskService.class)
                .setPeriod(period).setFlex(flex).setTag(periodicTag)
                .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED).setRequiresCharging(false).build();
        // Schedule task with tag "periodic." This ensure that only the stocks present in the DB
        // are updated.
        GcmNetworkManager.getInstance(this).schedule(periodicTask);
    }

    if (!Utils.isNetworkAvailable(getApplicationContext())) {
        networkToast();
    }
}

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url//from   ww  w  .  ja  va2s. c  o  m
 * @param features
 * @return
 */
public String showWebPage(final String url, final Options features) {
    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new ThemeableBrowserDialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar,
                    features.hardwareback);
            if (!features.disableAnimation) {
                dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            }
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setThemeableBrowser(getThemeableBrowser());

            // Main container layout
            ViewGroup main = null;

            if (features.fullscreen) {
                main = new FrameLayout(cordova.getActivity());
            } else {
                main = new LinearLayout(cordova.getActivity());
                ((LinearLayout) main).setOrientation(LinearLayout.VERTICAL);
            }

            // Toolbar layout
            Toolbar toolbarDef = features.toolbar;
            FrameLayout toolbar = new FrameLayout(cordova.getActivity());
            toolbar.setBackgroundColor(hexStringToColor(
                    toolbarDef != null && toolbarDef.color != null ? toolbarDef.color : "#ffffffff"));
            toolbar.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
                    dpToPixels(toolbarDef != null ? toolbarDef.height : TOOLBAR_DEF_HEIGHT)));

            if (toolbarDef != null && (toolbarDef.image != null || toolbarDef.wwwImage != null)) {
                try {
                    Drawable background = getImage(toolbarDef.image, toolbarDef.wwwImage,
                            toolbarDef.wwwImageDensity);
                    setBackground(toolbar, background);
                } catch (Resources.NotFoundException e) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.image));
                } catch (IOException ioe) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.wwwImage));
                }
            }

            // Left Button Container layout
            LinearLayout leftButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams leftButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            leftButtonContainerParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
            leftButtonContainer.setLayoutParams(leftButtonContainerParams);
            leftButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Right Button Container layout
            LinearLayout rightButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams rightButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            rightButtonContainerParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
            rightButtonContainer.setLayoutParams(rightButtonContainerParams);
            rightButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // 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.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;
                }
            });

            // Back button
            final Button back = createButton(features.backButton, "back button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.backButton, inAppWebView.getUrl());

                    if (features.backButtonCanClose && !canGoBack()) {
                        closeDialog();
                    } else {
                        goBack();
                    }
                }
            });

            if (back != null) {
                back.setEnabled(features.backButtonCanClose);
            }

            // Forward button
            final Button forward = createButton(features.forwardButton, "forward button",
                    new View.OnClickListener() {
                        public void onClick(View v) {
                            emitButtonEvent(features.forwardButton, inAppWebView.getUrl());

                            goForward();
                        }
                    });

            if (forward != null) {
                forward.setEnabled(false);
            }

            // Close/Done button
            Button close = createButton(features.closeButton, "close button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.closeButton, inAppWebView.getUrl());
                    closeDialog();
                }
            });

            // Menu button
            Spinner menu = features.menu != null ? new MenuSpinner(cordova.getActivity()) : null;
            if (menu != null) {
                menu.setLayoutParams(
                        new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                menu.setContentDescription("menu button");
                setButtonImages(menu, features.menu, DISABLED_ALPHA);

                // We are not allowed to use onClickListener for Spinner, so we will use
                // onTouchListener as a fallback.
                menu.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (event.getAction() == MotionEvent.ACTION_UP) {
                            emitButtonEvent(features.menu, inAppWebView.getUrl());
                        }
                        return false;
                    }
                });

                if (features.menu.items != null) {
                    HideSelectedAdapter<EventLabel> adapter = new HideSelectedAdapter<EventLabel>(
                            cordova.getActivity(), android.R.layout.simple_spinner_item, features.menu.items);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    menu.setAdapter(adapter);
                    menu.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                            if (inAppWebView != null && i < features.menu.items.length) {
                                emitButtonEvent(features.menu.items[i], inAppWebView.getUrl(), i);
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> adapterView) {
                        }
                    });
                }
            }

            // Title
            final TextView title = features.title != null ? new TextView(cordova.getActivity()) : null;
            final TextView subtitle = features.title != null ? new TextView(cordova.getActivity()) : null;
            if (title != null) {
                FrameLayout.LayoutParams titleParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                        LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                title.setLayoutParams(titleParams);
                title.setSingleLine();
                title.setEllipsize(TextUtils.TruncateAt.END);
                title.setGravity(Gravity.CENTER | Gravity.TOP);
                title.setTextColor(
                        hexStringToColor(features.title.color != null ? features.title.color : "#000000ff"));
                title.setTypeface(title.getTypeface(), Typeface.BOLD);
                title.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);

                FrameLayout.LayoutParams subtitleParams = new FrameLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                subtitle.setLayoutParams(subtitleParams);
                subtitle.setSingleLine();
                subtitle.setEllipsize(TextUtils.TruncateAt.END);
                subtitle.setGravity(Gravity.CENTER | Gravity.BOTTOM);
                subtitle.setTextColor(hexStringToColor(
                        features.title.subColor != null ? features.title.subColor : "#000000ff"));
                subtitle.setTextSize(TypedValue.COMPLEX_UNIT_PT, 6);
                subtitle.setVisibility(View.GONE);

                if (features.title.staticText != null) {
                    title.setGravity(Gravity.CENTER);
                    title.setText(features.title.staticText);
                } else {
                    subtitle.setVisibility(View.VISIBLE);
                }
            }

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            final ViewGroup.LayoutParams inAppWebViewParams = features.fullscreen
                    ? new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
                    : new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
            if (!features.fullscreen) {
                ((LinearLayout.LayoutParams) inAppWebViewParams).weight = 1;
            }
            inAppWebView.setLayoutParams(inAppWebViewParams);
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new ThemeableBrowserClient(thatWebView, new PageLoadListener() {

                @Override
                public void onPageStarted(String url) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle
                            && features.title.loadingText != null) {
                        title.setText(features.title.loadingText);
                        subtitle.setText(url);
                    }
                }

                @Override
                public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle) {
                        title.setText(inAppWebView.getTitle());
                        subtitle.setText(inAppWebView.getUrl());
                    }

                    if (back != null) {
                        back.setEnabled(canGoBack || features.backButtonCanClose);
                    }

                    if (forward != null) {
                        forward.setEnabled(canGoForward);
                    }
                }
            });
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(features.zoom);
            settings.setDisplayZoomControls(false);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

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

            if (features.clearcache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (features.clearsessioncache) {
                CookieManager.getInstance().removeSessionCookie();
            }

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

            // Add buttons to either leftButtonsContainer or
            // rightButtonsContainer according to user's alignment
            // configuration.
            int leftContainerWidth = 0;
            int rightContainerWidth = 0;

            if (features.customButtons != null) {
                for (int i = 0; i < features.customButtons.length; i++) {
                    final BrowserButton buttonProps = features.customButtons[i];
                    final int index = i;
                    Button button = createButton(buttonProps, String.format("custom button at %d", i),
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (inAppWebView != null) {
                                        emitButtonEvent(buttonProps, inAppWebView.getUrl(), index);
                                    }
                                }
                            });

                    if (ALIGN_RIGHT.equals(buttonProps.align)) {
                        rightButtonContainer.addView(button);
                        rightContainerWidth += button.getLayoutParams().width;
                    } else {
                        leftButtonContainer.addView(button, 0);
                        leftContainerWidth += button.getLayoutParams().width;
                    }
                }
            }

            // Back and forward buttons must be added with special ordering logic such
            // that back button is always on the left of forward button if both buttons
            // are on the same side.
            if (forward != null && features.forwardButton != null
                    && !ALIGN_RIGHT.equals(features.forwardButton.align)) {
                leftButtonContainer.addView(forward, 0);
                leftContainerWidth += forward.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && ALIGN_RIGHT.equals(features.backButton.align)) {
                rightButtonContainer.addView(back);
                rightContainerWidth += back.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && !ALIGN_RIGHT.equals(features.backButton.align)) {
                leftButtonContainer.addView(back, 0);
                leftContainerWidth += back.getLayoutParams().width;
            }

            if (forward != null && features.forwardButton != null
                    && ALIGN_RIGHT.equals(features.forwardButton.align)) {
                rightButtonContainer.addView(forward);
                rightContainerWidth += forward.getLayoutParams().width;
            }

            if (menu != null) {
                if (features.menu != null && ALIGN_RIGHT.equals(features.menu.align)) {
                    rightButtonContainer.addView(menu);
                    rightContainerWidth += menu.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(menu, 0);
                    leftContainerWidth += menu.getLayoutParams().width;
                }
            }

            if (close != null) {
                if (features.closeButton != null && ALIGN_RIGHT.equals(features.closeButton.align)) {
                    rightButtonContainer.addView(close);
                    rightContainerWidth += close.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(close, 0);
                    leftContainerWidth += close.getLayoutParams().width;
                }
            }

            // Add the views to our toolbar
            toolbar.addView(leftButtonContainer);
            // Don't show address bar.
            // toolbar.addView(edittext);
            toolbar.addView(rightButtonContainer);

            if (title != null) {
                int titleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams titleParams = (FrameLayout.LayoutParams) title.getLayoutParams();
                titleParams.setMargins(titleMargin, 8, titleMargin, 0);
                toolbar.addView(title);
            }

            if (subtitle != null) {
                int subtitleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams subtitleParams = (FrameLayout.LayoutParams) subtitle.getLayoutParams();
                subtitleParams.setMargins(subtitleMargin, 0, subtitleMargin, 8);
                toolbar.addView(subtitle);
            }

            if (features.fullscreen) {
                // If full screen mode, we have to add inAppWebView before adding toolbar.
                main.addView(inAppWebView);
            }

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

            if (!features.fullscreen) {
                // If not full screen, we add inAppWebView after adding toolbar.
                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 (features.hidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.ppshein.PlanetMyanmarDictionary.common.java

public static void addBookmark(String notedword, Context context) {
    try {//from w w  w  . j  a v  a2 s . c o m

        DatabaseUtil dbUtil = new DatabaseUtil(context);

        dbUtil.open();
        Cursor cursor = dbUtil.fetchBookmark(notedword);
        String getReturn = cursor.getString(1);
        cursor.close();
        dbUtil.close();
        Log.v("Existing Bookmarks", getReturn);
    } catch (Exception e) {
        DatabaseUtil dbUtil = new DatabaseUtil(context);
        dbUtil.open();
        dbUtil.insertBookmark(notedword);
        dbUtil.close();
        Toast toast = Toast.makeText(context, "Successfully bookmarked", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
}

From source file:com.actionbarsherlock.internal.widget.ActionBarView.java

public void setNavigationMode(int mode) {
    final int oldMode = mNavigationMode;
    if (mode != oldMode) {
        switch (oldMode) {
        case ActionBar.NAVIGATION_MODE_LIST:
            if (mListNavLayout != null) {
                removeView(mListNavLayout);
            }/*from   w ww  .  j av  a  2  s  .c o m*/
            break;
        case ActionBar.NAVIGATION_MODE_TABS:
            if (mTabScrollView != null && mIncludeTabs) {
                removeView(mTabScrollView);
            }
        }

        switch (mode) {
        case ActionBar.NAVIGATION_MODE_LIST:
            if (mSpinner == null) {
                mSpinner = new IcsSpinner(mContext, null, R.attr.actionDropDownStyle);
                mListNavLayout = (IcsLinearLayout) LayoutInflater.from(mContext)
                        .inflate(R.layout.abs__action_bar_tab_bar_view, null);
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.MATCH_PARENT);
                params.gravity = Gravity.CENTER;
                mListNavLayout.addView(mSpinner, params);
            }
            if (mSpinner.getAdapter() != mSpinnerAdapter) {
                mSpinner.setAdapter(mSpinnerAdapter);
            }
            mSpinner.setOnItemSelectedListener(mNavItemSelectedListener);
            addView(mListNavLayout);
            break;
        case ActionBar.NAVIGATION_MODE_TABS:
            if (mTabScrollView != null && mIncludeTabs) {
                addView(mTabScrollView);
            }
            break;
        }
        mNavigationMode = mode;
        requestLayout();
    }
}

From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java

/**
 * Applies current thumb tint from {@link Decorator#mTintInfo} to the current thumb drawable.
 * <p>/*from  www  . j  a v  a 2  s .  c o m*/
 * <b>Note</b>, that for post {@link android.os.Build.VERSION_CODES#LOLLIPOP LOLLIPOP} this
 * method does nothing.
 */
@SuppressWarnings("ConstantConditions")
private void applyThumbTint() {
    this.ensureDecorator();
    if (UiConfig.MATERIALIZED || mThumb == null || !mDecorator.hasTintInfo()) {
        return;
    }
    final Drawable thumb = mThumb instanceof ScaleDrawable ? ((ScaleDrawable) mThumb).getDrawable() : mThumb;
    final SeekBarTintInfo tintInfo = mDecorator.getTintInfo();
    if ((!tintInfo.hasTintList && !tintInfo.hasTintMode)) {
        return;
    }
    final boolean isTintDrawable = thumb instanceof TintDrawable;
    final TintDrawable tintDrawable = isTintDrawable ? (TintDrawable) thumb : new TintDrawable(thumb);
    if (tintInfo.hasTintList) {
        tintDrawable.setTintList(tintInfo.tintList);
    }
    if (tintInfo.hasTintMode) {
        tintDrawable.setTintMode(tintInfo.tintMode);
    }
    if (tintDrawable.isStateful()) {
        tintDrawable.setState(getDrawableState());
    }
    if (isTintDrawable) {
        return;
    }
    final int thumbOffset = getThumbOffset();
    this.mThumb = mDecorator.hasPrivateFlag(PFLAG_DISCRETE)
            ? mAnimations.makeThumbScaleable(tintDrawable, Gravity.CENTER)
            : tintDrawable;

    super.setThumb(mThumb);
    tintDrawable.attachCallback();
    setThumbOffset(thumbOffset);
}

From source file:co.taqat.call.CallActivity.java

public void displayCustomToast(final String message, final int duration) {
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot));

    TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
    toastText.setText(message);/*from w w w .j  av  a2s.  co  m*/

    final Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(duration);
    toast.setView(layout);
    toast.show();
}

From source file:com.hybris.mobile.app.commerce.fragment.ProductDetailFragmentBase.java

/**
 * Hide UI element to only display Image ViewPager to allow interaction with the ImageView
 *
 * @param isZoomed Zoom to ImageView other wise reset image
 *//*ww w  .  j  a  v  a 2s.  c  om*/
protected void zoomImage(boolean isZoomed) {
    final ZoomImageView zoomImageView = new ZoomImageView(getActivity());
    zoomImageView.setScaleType(ZoomImageView.ScaleType.CENTER_INSIDE);
    zoomImageView.setClickable(true);
    zoomImageView.setFocusableInTouchMode(true);
    zoomImageView.setVisibility(View.GONE);
    zoomImageView.setContentDescription("product_detail_zoom_image_view");

    if (!mProduct.getImagesGallery().isEmpty() && mCurrentIndicator < mProduct.getImagesGallery().size()
            && StringUtils.isNotBlank(mProduct.getImagesGallery().get(mCurrentIndicator).getUrl())) {
        CommerceApplication.getContentServiceHelper().loadImage(
                mProduct.getImagesGallery().get(mCurrentIndicator).getUrl(), null, zoomImageView, 0, 0, true,
                null, false);
    }

    if (isZoomed) {
        getActivity().getActionBar().hide();

        mProductDetailScrollView.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
        mScrollViewLayout.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
        mImageLayout.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
        mImageLayout.setGravity(Gravity.CENTER);

        zoomImageView.setVisibility(View.VISIBLE);
        mLayoutIndicator.setVisibility(View.GONE);
        mImageLayout.addView(zoomImageView);
        mViewPager.setVisibility(View.GONE);
        mMiddleSection.setVisibility(View.GONE);
        mBottomSection.setVisibility(View.GONE);
        mViewDivider.setVisibility(View.GONE);
    } else {
        getActivity().getActionBar().show();

        mProductDetailScrollView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
        mScrollViewLayout.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
        mImageLayout.getLayoutParams().height = (int) getResources()
                .getDimension(R.dimen.product_detail_viewpager_height);

        mImageLayout.removeAllViewsInLayout();
        mImageLayout.addView(mViewPager);
        mImageLayout.addView(mLayoutIndicator);
        mLayoutIndicator.setVisibility(View.VISIBLE);
        mViewPager.setVisibility(View.VISIBLE);
        mMiddleSection.setVisibility(View.VISIBLE);
        mBottomSection.setVisibility(View.VISIBLE);
        mViewDivider.setVisibility(View.VISIBLE);
    }
}

From source file:com.insthub.O2OMobile.Activity.C1_PublishOrderActivity.java

/**
 * ?/* w  w  w .  java  2 s.  c o m*/
 */
private void stopRecording() {
    if (mTimer != null) {
        mTimer.cancel(); //??
    }
    mTimer = null;
    if (mRecorder != null) {
        try {
            mRecorder.stop();
            mRecorder.reset();
            mRecorder.release();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }
    }
    mRecorder = null;

    MediaPlayer mp = MediaPlayer.create(this, Uri.parse(mFileName));
    if (null != mp) {
        int duration = mp.getDuration();//? ms
        if (duration > 3000) {
            mVoice.setVisibility(View.GONE);
            mVoicePlay.setVisibility(View.VISIBLE);
            mVoiceReset.setVisibility(View.VISIBLE);
        } else {
            ToastView toast = new ToastView(C1_PublishOrderActivity.this,
                    getString(R.string.record_time_too_short));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            File file = new File(newFileName());
            if (file.exists()) {
                file.delete();
            }
        }
        mp.release();
    }
    mVoice.setKeepScreenOn(false);
}

From source file:com.ccxt.whl.activity.SettingsFragmentCopy.java

/**
 * ?uri?/*from   w  ww .  ja  va2  s. c  o m*/
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    // String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getActivity().getContentResolver().query(selectedImage, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex("_data");
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        copyFile(picturePath, imageUri.getPath());
        cropImageUri(imageUri, 150, 150, USERPIC_REQUEST_CODE_CUT);
        //sendPicture(picturePath);
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(getActivity(), "?", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        copyFile(selectedImage.getPath(), imageUri.getPath());
        cropImageUri(imageUri, 150, 150, USERPIC_REQUEST_CODE_CUT);
        //sendPicture(file.getAbsolutePath());
    }
    /*if(getpathfromUri(uri)!=null&&getpathfromUri(imageUri)!=null){
        copyFile(getpathfromUri(uri),getpathfromUri(imageUri));
       }else{
    return;
       }*/
    //cropImageUri(selectedImage, 150, 150, USERPIC_REQUEST_CODE_CUT);

}