Example usage for android.widget FrameLayout FrameLayout

List of usage examples for android.widget FrameLayout FrameLayout

Introduction

In this page you can find the example usage for android.widget FrameLayout FrameLayout.

Prototype

public FrameLayout(@NonNull Context context) 

Source Link

Usage

From source file:dk.dr.radio.diverse.PagerSlidingTabStrip.java

private void addIconTabBdeTekstOgBillede(final int position, int resId, String title) {
      FrameLayout tabfl = new FrameLayout(getContext());
      ImageView tabi = new ImageView(getContext());
      tabi.setContentDescription(title);
      tabi.setImageResource(resId);//from   w ww  . j a va2  s .co  m
      tabi.setVisibility(View.INVISIBLE);
      TextView tabt = new TextView(getContext());
      tabt.setText(title);
      tabt.setTypeface(App.skrift_gibson);
      tabt.setGravity(Gravity.CENTER);
      tabt.setSingleLine();

      tabfl.addView(tabi);
      tabfl.addView(tabt);

      LayoutParams lp = (LayoutParams) tabi.getLayoutParams();
      lp.gravity = Gravity.CENTER;
      lp = (LayoutParams) tabt.getLayoutParams();
      lp.width = lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
      lp.gravity = Gravity.CENTER;

      addTab(position, tabfl);
  }

From source file:foam.mongoose.StarwispBuilder.java

public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) {

    try {/*w  w  w.  j a v a  2 s . c  o m*/
        String type = arr.getString(0);

        //Log.i("starwisp","building started "+type);

        if (type.equals("build-fragment")) {
            String name = arr.getString(1);
            int ID = arr.getInt(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            inner.setId(ID);
            FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(ID, fragment);
            fragmentTransaction.commit();
            parent.addView(inner);
            return;
        }

        if (type.equals("linear-layout")) {
            LinearLayout v = new LinearLayout(ctx);
            v.setId(arr.getInt(1));
            v.setOrientation(BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            //v.setPadding(2,2,2,2);
            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(5);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("frame-layout")) {
            FrameLayout v = new FrameLayout(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        /*
        if (type.equals("grid-layout")) {
        GridLayout v = new GridLayout(ctx);
        v.setId(arr.getInt(1));
        v.setRowCount(arr.getInt(2));
        //v.setColumnCount(arr.getInt(2));
        v.setOrientation(BuildOrientation(arr.getString(3)));
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
                
        parent.addView(v);
        JSONArray children = arr.getJSONArray(5);
        for (int i=0; i<children.length(); i++) {
            Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
        }
                
        return;
        }
        */

        if (type.equals("scroll-view")) {
            HorizontalScrollView v = new HorizontalScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("scroll-view-vert")) {
            ScrollView v = new ScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("view-pager")) {
            ViewPager v = new ViewPager(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.setOffscreenPageLimit(3);
            final JSONArray items = arr.getJSONArray(3);

            v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {

                @Override
                public int getCount() {
                    return items.length();
                }

                @Override
                public Fragment getItem(int position) {
                    try {
                        String fragname = items.getString(position);
                        return ActivityManager.GetFragment(fragname);
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                    return null;
                }
            });
            parent.addView(v);
            return;
        }

        if (type.equals("space")) {
            // Space v = new Space(ctx); (class not found runtime error??)
            TextView v = new TextView(ctx);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
        }

        if (type.equals("image-view")) {
            ImageView v = new ImageView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));

            String image = arr.getString(2);

            if (image.startsWith("/")) {
                Bitmap bitmap = BitmapFactory.decodeFile(image);
                v.setImageBitmap(bitmap);
            } else {
                int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName());
                v.setImageResource(id);
            }

            parent.addView(v);
        }

        if (type.equals("text-view")) {
            TextView v = new TextView(ctx);
            v.setId(arr.getInt(1));
            v.setText(Html.fromHtml(arr.getString(2)));
            v.setTextSize(arr.getInt(3));
            v.setMovementMethod(LinkMovementMethod.getInstance());
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            if (arr.length() > 5) {
                if (arr.getString(5).equals("left")) {
                    v.setGravity(Gravity.LEFT);
                } else {
                    if (arr.getString(5).equals("fill")) {
                        v.setGravity(Gravity.FILL);
                    } else {
                        v.setGravity(Gravity.CENTER);
                    }
                }
            } else {
                v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            parent.addView(v);
        }

        if (type.equals("debug-text-view")) {
            TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null);
            //                v.setBackgroundResource(R.color.black);
            v.setId(arr.getInt(1));
            //                v.setText(Html.fromHtml(arr.getString(2)));
            //                v.setTextColor(R.color.white);
            //                v.setTextSize(arr.getInt(3));
            //                v.setMovementMethod(LinkMovementMethod.getInstance());
            //                v.setMaxLines(10);
            //                v.setVerticalScrollBarEnabled(true);
            //                v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            //v.setMovementMethod(new ScrollingMovementMethod());

            /*
            if (arr.length()>5) {
            if (arr.getString(5).equals("left")) {
                v.setGravity(Gravity.LEFT);
            } else {
                if (arr.getString(5).equals("fill")) {
                    v.setGravity(Gravity.FILL);
                } else {
                    v.setGravity(Gravity.CENTER);
                }
            }
            } else {
            v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/
            parent.addView(v);
        }

        if (type.equals("web-view")) {
            WebView v = new WebView(ctx);
            v.setId(arr.getInt(1));
            v.setVerticalScrollBarEnabled(false);
            v.loadData(arr.getString(2), "text/html", "utf-8");
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            parent.addView(v);
        }

        if (type.equals("edit-text")) {
            final EditText v = new EditText(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));

            String inputtype = arr.getString(4);
            if (inputtype.equals("text")) {
                //v.setInputType(InputType.TYPE_CLASS_TEXT);
            } else if (inputtype.equals("numeric")) {
                v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            } else if (inputtype.equals("email")) {
                v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
            }

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setSingleLine(true);

            v.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\"");
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("button")) {
            Button v = new Button(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });
            parent.addView(v);
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = new ToggleButton(ctx);
            if (arr.getString(5).equals("fancy")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null);
            }

            if (arr.getString(5).equals("yes")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null);
            }

            if (arr.getString(5).equals("maybe")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null);
            }

            if (arr.getString(5).equals("no")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null);
            }

            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(6);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String arg = "#f";
                    if (((ToggleButton) v).isChecked())
                        arg = "#t";
                    CallbackArgs(ctx, ctxname, v.getId(), arg);
                }
            });
            parent.addView(v);
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            v.setId(arr.getInt(1));
            v.setMax(arr.getInt(2));
            v.setProgress(arr.getInt(2) / 2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            final String fn = arr.getString(4);

            v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar v, int a, boolean s) {
                    CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a));
                }

                public void onStartTrackingTouch(SeekBar v) {
                }

                public void onStopTrackingTouch(SeekBar v) {
                }
            });
            parent.addView(v);
        }

        if (type.equals("spinner")) {
            Spinner v = new Spinner(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            final JSONArray items = arr.getJSONArray(2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            ArrayList<String> spinnerArray = new ArrayList<String>();

            for (int i = 0; i < items.length(); i++) {
                spinnerArray.add(items.getString(i));
            }

            ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item,
                    spinnerArray) {
                public View getView(int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                    return v;
                }
            };

            spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout);

            v.setAdapter(spinnerArrayAdapter);
            v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                    try {
                        CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\"");
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                }

                public void onNothingSelected(AdapterView<?> v) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("canvas")) {
            StarwispCanvas v = new StarwispCanvas(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.SetDrawList(arr.getJSONArray(3));
            parent.addView(v);
        }

        if (type.equals("camera-preview")) {
            PictureTaker pt = new PictureTaker();
            CameraPreview v = new CameraPreview(ctx, pt);
            final int wid = arr.getInt(1);
            v.setId(wid);

            //              LinearLayout.LayoutParams lp =
            //  new LinearLayout.LayoutParams(minWidth, minHeight, 1);

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));

            //                v.setLayoutParams(lp);
            parent.addView(v);
        }

        if (type.equals("button-grid")) {
            LinearLayout horiz = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            final String buttontype = arr.getString(2);
            horiz.setId(id);
            horiz.setOrientation(LinearLayout.HORIZONTAL);
            parent.addView(horiz);
            int height = arr.getInt(3);
            int textsize = arr.getInt(4);
            LinearLayout.LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5));
            JSONArray buttons = arr.getJSONArray(6);
            int count = buttons.length();
            int vertcount = 0;
            LinearLayout vert = null;

            for (int i = 0; i < count; i++) {
                JSONArray button = buttons.getJSONArray(i);

                if (vertcount == 0) {
                    vert = new LinearLayout(ctx);
                    vert.setId(0);
                    vert.setOrientation(LinearLayout.VERTICAL);
                    horiz.addView(vert);
                }
                vertcount = (vertcount + 1) % height;

                if (buttontype.equals("button")) {
                    Button b = new Button(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                        }
                    });
                    vert.addView(b);
                } else if (buttontype.equals("toggle")) {
                    ToggleButton b = new ToggleButton(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            String arg = "#f";
                            if (((ToggleButton) v).isChecked())
                                arg = "#t";
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                        }
                    });
                    vert.addView(b);
                }
            }
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString());
    }

    //Log.i("starwisp","building ended");

}

From source file:org.godotengine.godot.Godot.java

public void onVideoInit() {
    boolean use_gl3 = getGLESVersionCode() >= 0x00030000;

    //mView = new GodotView(getApplication(),io,use_gl3);
    //setContentView(mView);

    layout = new FrameLayout(this);
    layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    setContentView(layout);//from   w  ww. j a va2s.co m

    // GodotEditText layout
    GodotEditText edittext = new GodotEditText(this);
    edittext.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    // ...add to FrameLayout
    layout.addView(edittext);

    mView = new GodotView(getApplication(), io, use_gl3, use_32_bits, use_debug_opengl, this);
    layout.addView(mView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    edittext.setView(mView);
    io.setEdit(edittext);

    final Godot godot = this;
    mView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            Point fullSize = new Point();
            godot.getWindowManager().getDefaultDisplay().getSize(fullSize);
            Rect gameSize = new Rect();
            godot.mView.getWindowVisibleDisplayFrame(gameSize);

            final int keyboardHeight = fullSize.y - gameSize.bottom;
            GodotLib.setVirtualKeyboardHeight(keyboardHeight);
        }
    });

    final String[] current_command_line = command_line;
    mView.queueEvent(new Runnable() {
        @Override
        public void run() {
            GodotLib.setup(current_command_line);
            setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on")));
        }
    });
}

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static AlertDialog.Builder createTextBoxDialog(Context context, int newtag_title, int newtag_hint,
        final OnTextBoxDialogClick onClickListener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    FrameLayout container = new FrameLayout(context);
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER_VERTICAL;
    container.setMinimumHeight(AndroidUtilsUI.dpToPx(100));
    int padding = AndroidUtilsUI.dpToPx(20);
    params.leftMargin = padding;/*from  w w w . j  av a  2s  .c  o m*/
    params.rightMargin = padding;

    final MaterialEditText textView = AndroidUtilsUI.createFancyTextView(context);
    textView.setHint(newtag_hint);
    textView.setFloatingLabelText(context.getResources().getString(newtag_hint));
    textView.setSingleLine();
    textView.setLayoutParams(params);

    container.addView(textView);

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        builder.setInverseBackgroundForced(true);
    }

    builder.setView(container);
    builder.setTitle(newtag_title);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            onClickListener.onClick(dialog, which, textView);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    return builder;
}

From source file:org.quantumbadger.redreader.fragments.WebViewFragment.java

@SuppressLint("NewApi")
@Override/*from w  w w.  j a  v  a 2 s.  c om*/
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    mActivity = (AppCompatActivity) getActivity();

    CookieSyncManager.createInstance(mActivity);

    outer = (FrameLayout) inflater.inflate(R.layout.web_view_fragment, null);

    final RedditPost src_post = getArguments().getParcelable("post");
    final RedditPreparedPost post;

    if (src_post != null) {

        final RedditParsedPost parsedPost = new RedditParsedPost(src_post, false);

        post = new RedditPreparedPost(mActivity, CacheManager.getInstance(mActivity), 0, parsedPost, -1, false,
                false);

    } else {
        post = null;
    }

    webView = (WebViewFixed) outer.findViewById(R.id.web_view_fragment_webviewfixed);
    final FrameLayout loadingViewFrame = (FrameLayout) outer
            .findViewById(R.id.web_view_fragment_loadingview_frame);

    /*handle download links show an alert box to load this outside the internal browser*/
    webView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(final String url, String userAgent, String contentDisposition,
                String mimetype, long contentLength) {
            {
                new AlertDialog.Builder(mActivity).setTitle(R.string.download_link_title)
                        .setMessage(R.string.download_link_message)
                        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Intent i = new Intent(Intent.ACTION_VIEW);
                                i.setData(Uri.parse(url));
                                getContext().startActivity(i);
                                mActivity.onBackPressed(); //get back from internal browser
                            }
                        }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                mActivity.onBackPressed(); //get back from internal browser
                            }
                        }).setIcon(android.R.drawable.ic_dialog_alert).show();
            }
        }
    });
    /*handle download links end*/

    progressView = new ProgressBar(mActivity, null, android.R.attr.progressBarStyleHorizontal);
    loadingViewFrame.addView(progressView);
    loadingViewFrame.setPadding(General.dpToPixels(mActivity, 10), 0, General.dpToPixels(mActivity, 10), 0);

    final WebSettings settings = webView.getSettings();

    settings.setBuiltInZoomControls(true);
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(false);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setDomStorageEnabled(true);

    if (AndroidApi.isHoneyCombOrLater()) {
        settings.setDisplayZoomControls(false);
    }

    // TODO handle long clicks

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, final int newProgress) {

            super.onProgressChanged(view, newProgress);

            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                @Override
                public void run() {
                    progressView.setProgress(newProgress);
                    progressView.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);
                }
            });
        }
    });

    if (mUrl != null) {
        webView.loadUrl(mUrl);
    } else {
        webView.loadDataWithBaseURL("https://reddit.com/", html, "text/html; charset=UTF-8", null, null);
    }

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(final WebView view, final String url) {

            if (url == null)
                return false;

            if (url.startsWith("data:")) {
                // Prevent imgur bug where we're directed to some random data URI
                return true;
            }

            // Go back if loading same page to prevent redirect loops.
            if (goingBack && currentUrl != null && url.equals(currentUrl)) {

                General.quickToast(mActivity,
                        String.format(Locale.US, "Handling redirect loop (level %d)", -lastBackDepthAttempt),
                        Toast.LENGTH_SHORT);

                lastBackDepthAttempt--;

                if (webView.canGoBackOrForward(lastBackDepthAttempt)) {
                    webView.goBackOrForward(lastBackDepthAttempt);
                } else {
                    mActivity.finish();
                }
            } else {

                if (RedditURLParser.parse(Uri.parse(url)) != null) {
                    LinkHandler.onLinkClicked(mActivity, url, false);
                } else {
                    webView.loadUrl(url);
                    currentUrl = url;
                }
            }

            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);

            if (mUrl != null && url != null) {

                final AppCompatActivity activity = mActivity;

                if (activity != null) {
                    activity.setTitle(url);
                }
            }
        }

        @Override
        public void onPageFinished(final WebView view, final String url) {
            super.onPageFinished(view, url);

            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {

                    AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                        @Override
                        public void run() {

                            if (currentUrl == null || url == null)
                                return;

                            if (!url.equals(view.getUrl()))
                                return;

                            if (goingBack && url.equals(currentUrl)) {

                                General.quickToast(mActivity, String.format(Locale.US,
                                        "Handling redirect loop (level %d)", -lastBackDepthAttempt));

                                lastBackDepthAttempt--;

                                if (webView.canGoBackOrForward(lastBackDepthAttempt)) {
                                    webView.goBackOrForward(lastBackDepthAttempt);
                                } else {
                                    mActivity.finish();
                                }

                            } else {
                                goingBack = false;
                            }
                        }
                    });
                }
            }, 1000);
        }

        @Override
        public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
            super.doUpdateVisitedHistory(view, url, isReload);
        }
    });

    final FrameLayout outerFrame = new FrameLayout(mActivity);
    outerFrame.addView(outer);

    if (post != null) {

        final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(mActivity);

        final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(mActivity,
                new BezelSwipeOverlay.BezelSwipeListener() {
                    @Override
                    public boolean onSwipe(@BezelSwipeOverlay.SwipeEdge int edge) {

                        toolbarOverlay.setContents(post.generateToolbar(mActivity, false, toolbarOverlay));
                        toolbarOverlay.show(
                                edge == BezelSwipeOverlay.LEFT ? SideToolbarOverlay.SideToolbarPosition.LEFT
                                        : SideToolbarOverlay.SideToolbarPosition.RIGHT);
                        return true;
                    }

                    @Override
                    public boolean onTap() {

                        if (toolbarOverlay.isShown()) {
                            toolbarOverlay.hide();
                            return true;
                        }

                        return false;
                    }
                });

        outerFrame.addView(bezelOverlay);
        outerFrame.addView(toolbarOverlay);

        bezelOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        bezelOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

        toolbarOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        toolbarOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
    }

    return outerFrame;
}

From source file:de.grobox.liberario.TripsActivity.java

private void addTrips(final TableLayout main, List<Trip> trip_list, boolean append) {
    if (trip_list != null) {
        // reverse order of trips if they should be prepended
        if (!append) {
            ArrayList<Trip> tempResults = new ArrayList<Trip>(trip_list);
            Collections.reverse(tempResults);
            trip_list = tempResults;/* www .  j a v a 2s  . c o m*/
        }

        for (final Trip trip : trip_list) {
            final LinearLayout trip_layout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.trip,
                    null);
            TableRow row = (TableRow) trip_layout.findViewById(R.id.tripTableRow);

            // Locations
            TextView fromView = (TextView) row.findViewById(R.id.fromView);
            fromView.setText(trip.from.uniqueShortName());
            TextView toView = ((TextView) row.findViewById(R.id.toView));
            toView.setText(trip.to.uniqueShortName());

            // Departure Time and Delay
            TextView departureTimeView = (TextView) row.findViewById(R.id.departureTimeView);
            TextView departureDelayView = (TextView) row.findViewById(R.id.departureDelayView);
            if (trip.getFirstPublicLeg() != null) {
                LiberarioUtils.setDepartureTimes(this, departureTimeView, departureDelayView,
                        trip.getFirstPublicLeg().departureStop);
            } else {
                departureTimeView.setText(DateUtils.getTime(this, trip.getFirstDepartureTime()));
            }

            // Arrival Time and Delay
            TextView arrivalTimeView = (TextView) row.findViewById(R.id.arrivalTimeView);
            TextView arrivalDelayView = (TextView) row.findViewById(R.id.arrivalDelayView);
            if (trip.getLastPublicLeg() != null) {
                LiberarioUtils.setArrivalTimes(this, arrivalTimeView, arrivalDelayView,
                        trip.getLastPublicLeg().arrivalStop);
            } else {
                arrivalTimeView.setText(DateUtils.getTime(this, trip.getLastArrivalTime()));
            }

            // Duration
            TextView durationView = (TextView) trip_layout.findViewById(R.id.durationView);
            durationView
                    .setText(DateUtils.getDuration(trip.getFirstDepartureTime(), trip.getLastArrivalTime()));

            // Transports
            FlowLayout lineLayout = (FlowLayout) trip_layout.findViewById(R.id.lineLayout);

            // for each leg
            for (final Leg leg : trip.legs) {
                if (leg instanceof Trip.Public) {
                    LiberarioUtils.addLineBox(this, lineLayout, ((Public) leg).line);
                } else if (leg instanceof Trip.Individual) {
                    LiberarioUtils.addWalkingBox(this, lineLayout);
                }
            }

            // remember trip in view for onClick event
            trip_layout.setTag(trip);

            // make trip details fold out and in on click
            trip_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    View v = main.getChildAt(main.indexOfChild(view) + 1);

                    if (v != null) {
                        if (v.getVisibility() == View.GONE) {
                            v.setVisibility(View.VISIBLE);
                        } else if (v.getVisibility() == View.VISIBLE) {
                            v.setVisibility(View.GONE);
                        }
                    }
                }

            });
            trip_layout.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View view) {
                    selectTrip(view, trip_layout);
                    return true;
                }
            });

            // show more button for trip details
            final ImageView showMoreView = (ImageView) trip_layout.findViewById(R.id.showMoreView);
            showMoreView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    selectTrip(view, trip_layout);
                }
            });

            // Create container for trip details fragment
            FrameLayout fragmentContainer = new FrameLayout(this);
            fragmentContainer.setId(mContainerId);
            fragmentContainer.setVisibility(View.GONE);

            // Create a new Fragment to be placed in the activity layout
            TripDetailFragment tripDetailFragment = new TripDetailFragment();

            // In case this activity was started with special instructions from an
            // Intent, pass the Intent's extras to the fragment as arguments
            Bundle bundle = new Bundle();
            bundle.putSerializable("de.schildbach.pte.dto.Trip", trip);
            bundle.putSerializable("de.schildbach.pte.dto.Trip.from", from);
            bundle.putSerializable("de.schildbach.pte.dto.Trip.to", to);
            tripDetailFragment.setArguments(bundle);

            // Add the fragment to the 'fragment_container' FrameLayout
            getSupportFragmentManager().beginTransaction().add(mContainerId, tripDetailFragment).commit();

            mContainerId++;

            if (append) {
                trip_layout.addView(LiberarioUtils.getDivider(this));
                main.addView(trip_layout);
                main.addView(fragmentContainer);
            } else {
                trip_layout.addView(LiberarioUtils.getDivider(this), 0);
                main.addView(trip_layout, 0);
                main.addView(fragmentContainer, 1);
            }
        } // end foreach trip

    } else {
        // TODO offer option to query again for trips
    }
}

From source file:org.pouyadr.ui.LocationActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (AndroidUtilities.isTablet()) {
        actionBar.setOccupyStatusBar(false);
    }//from w w w  .j a  va  2  s . c o m
    actionBar.setAddToContainer(messageObject != null);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == map_list_menu_map) {
                if (googleMap != null) {
                    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                }
            } else if (id == map_list_menu_satellite) {
                if (googleMap != null) {
                    googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
                }
            } else if (id == map_list_menu_hybrid) {
                if (googleMap != null) {
                    googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
                }
            } else if (id == share) {
                try {
                    double lat = messageObject.messageOwner.media.geo.lat;
                    double lon = messageObject.messageOwner.media.geo._long;
                    getParentActivity().startActivity(new Intent(android.content.Intent.ACTION_VIEW,
                            Uri.parse("geo:" + lat + "," + lon + "?q=" + lat + "," + lon)));
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    if (messageObject != null) {
        if (messageObject.messageOwner.media.title != null
                && messageObject.messageOwner.media.title.length() > 0) {
            actionBar.setTitle(messageObject.messageOwner.media.title);
            if (messageObject.messageOwner.media.address != null
                    && messageObject.messageOwner.media.address.length() > 0) {
                actionBar.setSubtitle(messageObject.messageOwner.media.address);
            }
        } else {
            actionBar.setTitle(LocaleController.getString("ChatLocation", R.string.ChatLocation));
        }
        menu.addItem(share, R.drawable.share);
    } else {
        actionBar.setTitle(LocaleController.getString("ShareLocation", R.string.ShareLocation));

        ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true)
                .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                    @Override
                    public void onSearchExpand() {
                        searching = true;
                        listView.setVisibility(View.GONE);
                        mapViewClip.setVisibility(View.GONE);
                        searchListView.setVisibility(View.VISIBLE);
                        searchListView.setEmptyView(emptyTextLayout);
                    }

                    @Override
                    public void onSearchCollapse() {
                        searching = false;
                        searchWas = false;
                        searchListView.setEmptyView(null);
                        listView.setVisibility(View.VISIBLE);
                        mapViewClip.setVisibility(View.VISIBLE);
                        searchListView.setVisibility(View.GONE);
                        emptyTextLayout.setVisibility(View.GONE);
                        searchAdapter.searchDelayed(null, null);
                    }

                    @Override
                    public void onTextChanged(EditText editText) {
                        if (searchAdapter == null) {
                            return;
                        }
                        String text = editText.getText().toString();
                        if (text.length() != 0) {
                            searchWas = true;
                        }
                        searchAdapter.searchDelayed(text, userLocation);
                    }
                });
        item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
    }

    ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
    item.addSubItem(map_list_menu_map, LocaleController.getString("Map", R.string.Map), 0);
    item.addSubItem(map_list_menu_satellite, LocaleController.getString("Satellite", R.string.Satellite), 0);
    item.addSubItem(map_list_menu_hybrid, LocaleController.getString("Hybrid", R.string.Hybrid), 0);
    fragmentView = new FrameLayout(context) {
        private boolean first = true;

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);

            if (changed) {
                fixLayoutInternal(first);
                first = false;
            }
        }
    };
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    locationButton = new ImageView(context);
    locationButton.setBackgroundResource(R.drawable.floating_user_states);
    locationButton.setImageResource(R.drawable.myloc_on);
    locationButton.setScaleType(ImageView.ScaleType.CENTER);
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed },
                ObjectAnimator
                        .ofFloat(locationButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                        .setDuration(200));
        animator.addState(new int[] {},
                ObjectAnimator
                        .ofFloat(locationButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                        .setDuration(200));
        locationButton.setStateListAnimator(animator);
        locationButton.setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }

    if (messageObject != null) {
        mapView = new MapView(context);
        frameLayout.setBackgroundDrawable(new MapPlaceholderDrawable());
        mapView.onCreate(null);
        try {
            MapsInitializer.initialize(context);
            //                googleMap = mapView.getMap();
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }

        FrameLayout bottomView = new FrameLayout(context);
        bottomView.setBackgroundResource(R.drawable.location_panel);
        frameLayout.addView(bottomView,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 60, Gravity.LEFT | Gravity.BOTTOM));
        bottomView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (userLocation != null) {
                    LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
                    if (googleMap != null) {
                        CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng,
                                googleMap.getMaxZoomLevel() - 4);
                        googleMap.animateCamera(position);
                    }
                }
            }
        });

        avatarImageView = new BackupImageView(context);
        avatarImageView.setRoundRadius(AndroidUtilities.dp(20));
        bottomView.addView(avatarImageView,
                LayoutHelper.createFrame(40, 40,
                        Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                        LocaleController.isRTL ? 0 : 12, 12, LocaleController.isRTL ? 12 : 0, 0));

        nameTextView = new TextView(context);
        nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        nameTextView.setTextColor(0xff212121);
        nameTextView.setMaxLines(1);
        nameTextView.setTypeface(AndroidUtilities.getTypeface(org.pouyadr.finalsoft.Fonts.CurrentFont()));
        nameTextView.setEllipsize(TextUtils.TruncateAt.END);
        nameTextView.setSingleLine(true);
        nameTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        bottomView.addView(nameTextView,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                        LocaleController.isRTL ? 12 : 72, 10, LocaleController.isRTL ? 72 : 12, 0));

        distanceTextView = new TextView(context);
        distanceTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        distanceTextView.setTextColor(0xff2f8cc9);
        distanceTextView.setMaxLines(1);
        distanceTextView.setEllipsize(TextUtils.TruncateAt.END);
        distanceTextView.setSingleLine(true);
        distanceTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        bottomView.addView(distanceTextView,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                        LocaleController.isRTL ? 12 : 72, 33, LocaleController.isRTL ? 72 : 12, 0));

        userLocation = new Location("network");
        userLocation.setLatitude(messageObject.messageOwner.media.geo.lat);
        userLocation.setLongitude(messageObject.messageOwner.media.geo._long);
        if (googleMap != null) {
            LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
            try {
                googleMap.addMarker(new MarkerOptions().position(latLng)
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)));
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
            CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 4);
            googleMap.moveCamera(position);
        }

        ImageView routeButton = new ImageView(context);
        routeButton.setBackgroundResource(R.drawable.floating_states);
        routeButton.setImageResource(R.drawable.navigate);
        routeButton.setScaleType(ImageView.ScaleType.CENTER);
        if (Build.VERSION.SDK_INT >= 21) {
            StateListAnimator animator = new StateListAnimator();
            animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator
                    .ofFloat(routeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                    .setDuration(200));
            animator.addState(new int[] {}, ObjectAnimator
                    .ofFloat(routeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                    .setDuration(200));
            routeButton.setStateListAnimator(animator);
            routeButton.setOutlineProvider(new ViewOutlineProvider() {
                @Override
                public void getOutline(View view, Outline outline) {
                    outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
                }
            });
        }
        frameLayout.addView(routeButton,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM,
                        LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 28));
        routeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= 23) {
                    Activity activity = getParentActivity();
                    if (activity != null) {
                        if (activity.checkSelfPermission(
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                            showPermissionAlert(true);
                            return;
                        }
                    }
                }
                if (myLocation != null) {
                    try {
                        Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                                Uri.parse(String.format(Locale.US,
                                        "http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
                                        myLocation.getLatitude(), myLocation.getLongitude(),
                                        messageObject.messageOwner.media.geo.lat,
                                        messageObject.messageOwner.media.geo._long)));
                        getParentActivity().startActivity(intent);
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
            }
        });

        frameLayout.addView(locationButton,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM,
                        LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 100));
        locationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= 23) {
                    Activity activity = getParentActivity();
                    if (activity != null) {
                        if (activity.checkSelfPermission(
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                            showPermissionAlert(true);
                            return;
                        }
                    }
                }
                if (myLocation != null && googleMap != null) {
                    googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                            new LatLng(myLocation.getLatitude(), myLocation.getLongitude()),
                            googleMap.getMaxZoomLevel() - 4));
                }
            }
        });
    } else {
        searchWas = false;
        searching = false;
        mapViewClip = new FrameLayout(context);
        mapViewClip.setBackgroundDrawable(new MapPlaceholderDrawable());
        if (adapter != null) {
            adapter.destroy();
        }
        if (searchAdapter != null) {
            searchAdapter.destroy();
        }

        listView = new ListView(context);
        listView.setAdapter(adapter = new LocationActivityAdapter(context));
        listView.setVerticalScrollBarEnabled(false);
        listView.setDividerHeight(0);
        listView.setDivider(null);
        frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (totalItemCount == 0) {
                    return;
                }
                updateClipView(firstVisibleItem);
            }
        });
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 1) {
                    if (delegate != null && userLocation != null) {
                        TLRPC.TL_messageMediaGeo location = new TLRPC.TL_messageMediaGeo();
                        location.geo = new TLRPC.TL_geoPoint();
                        location.geo.lat = userLocation.getLatitude();
                        location.geo._long = userLocation.getLongitude();
                        delegate.didSelectLocation(location);
                    }
                    finishFragment();
                } else {
                    TLRPC.TL_messageMediaVenue object = adapter.getItem(position);
                    if (object != null && delegate != null) {
                        delegate.didSelectLocation(object);
                    }
                    finishFragment();
                }
            }
        });
        adapter.setDelegate(new BaseLocationAdapter.BaseLocationAdapterDelegate() {
            @Override
            public void didLoadedSearchResult(ArrayList<TLRPC.TL_messageMediaVenue> places) {
                if (!wasResults && !places.isEmpty()) {
                    wasResults = true;
                }
            }
        });
        adapter.setOverScrollHeight(overScrollHeight);

        frameLayout.addView(mapViewClip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));

        mapView = new MapView(context) {
            @Override
            public boolean onInterceptTouchEvent(MotionEvent ev) {
                if (Build.VERSION.SDK_INT >= 11) {
                    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
                        if (animatorSet != null) {
                            animatorSet.cancel();
                        }
                        animatorSet = new AnimatorSet();
                        animatorSet.setDuration(200);
                        animatorSet.playTogether(
                                ObjectAnimator.ofFloat(markerImageView, "translationY",
                                        markerTop + -AndroidUtilities.dp(10)),
                                ObjectAnimator.ofFloat(markerXImageView, "alpha", 1.0f));
                        animatorSet.start();
                    } else if (ev.getAction() == MotionEvent.ACTION_UP) {
                        if (animatorSet != null) {
                            animatorSet.cancel();
                        }
                        animatorSet = new AnimatorSet();
                        animatorSet.setDuration(200);
                        animatorSet.playTogether(
                                ObjectAnimator.ofFloat(markerImageView, "translationY", markerTop),
                                ObjectAnimator.ofFloat(markerXImageView, "alpha", 0.0f));
                        animatorSet.start();
                    }
                }
                if (ev.getAction() == MotionEvent.ACTION_MOVE) {
                    if (!userLocationMoved) {
                        if (Build.VERSION.SDK_INT >= 11) {
                            AnimatorSet animatorSet = new AnimatorSet();
                            animatorSet.setDuration(200);
                            animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 1.0f));
                            animatorSet.start();
                        } else {
                            locationButton.setVisibility(VISIBLE);
                        }
                        userLocationMoved = true;
                    }
                    if (googleMap != null && userLocation != null) {
                        userLocation.setLatitude(googleMap.getCameraPosition().target.latitude);
                        userLocation.setLongitude(googleMap.getCameraPosition().target.longitude);
                    }
                    adapter.setCustomLocation(userLocation);
                }
                return super.onInterceptTouchEvent(ev);
            }
        };
        try {
            mapView.onCreate(null);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        try {
            MapsInitializer.initialize(context);
            //                googleMap = mapView.getMap();
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }

        View shadow = new View(context);
        shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
        mapViewClip.addView(shadow,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM));

        markerImageView = new ImageView(context);
        markerImageView.setImageResource(R.drawable.map_pin);
        mapViewClip.addView(markerImageView,
                LayoutHelper.createFrame(24, 42, Gravity.TOP | Gravity.CENTER_HORIZONTAL));

        if (Build.VERSION.SDK_INT >= 11) {
            markerXImageView = new ImageView(context);
            markerXImageView.setAlpha(0.0f);
            markerXImageView.setImageResource(R.drawable.place_x);
            mapViewClip.addView(markerXImageView,
                    LayoutHelper.createFrame(14, 14, Gravity.TOP | Gravity.CENTER_HORIZONTAL));
        }

        mapViewClip.addView(locationButton,
                LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60,
                        Build.VERSION.SDK_INT >= 21 ? 56 : 60,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM,
                        LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14));
        locationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Build.VERSION.SDK_INT >= 23) {
                    Activity activity = getParentActivity();
                    if (activity != null) {
                        if (activity.checkSelfPermission(
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                            showPermissionAlert(false);
                            return;
                        }
                    }
                }
                if (myLocation != null && googleMap != null) {
                    if (Build.VERSION.SDK_INT >= 11) {
                        AnimatorSet animatorSet = new AnimatorSet();
                        animatorSet.setDuration(200);
                        animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 0.0f));
                        animatorSet.start();
                    } else {
                        locationButton.setVisibility(View.INVISIBLE);
                    }
                    adapter.setCustomLocation(null);
                    userLocationMoved = false;
                    googleMap.animateCamera(CameraUpdateFactory
                            .newLatLng(new LatLng(myLocation.getLatitude(), myLocation.getLongitude())));
                }
            }
        });
        if (Build.VERSION.SDK_INT >= 11) {
            locationButton.setAlpha(0.0f);
        } else {
            locationButton.setVisibility(View.INVISIBLE);
        }

        emptyTextLayout = new LinearLayout(context);
        emptyTextLayout.setVisibility(View.GONE);
        emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
        frameLayout.addView(emptyTextLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 100, 0, 0));
        emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        TextView emptyTextView = new TextView(context);
        emptyTextView.setTextColor(0xff808080);
        emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        emptyTextView.setGravity(Gravity.CENTER);
        emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
        emptyTextLayout.addView(emptyTextView,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));

        FrameLayout frameLayoutEmpty = new FrameLayout(context);
        emptyTextLayout.addView(frameLayoutEmpty,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f));

        searchListView = new ListView(context);
        searchListView.setVisibility(View.GONE);
        searchListView.setDividerHeight(0);
        searchListView.setDivider(null);
        searchListView.setAdapter(searchAdapter = new LocationActivitySearchAdapter(context));
        frameLayout.addView(searchListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
        searchListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
                    AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {

            }
        });
        searchListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TLRPC.TL_messageMediaVenue object = searchAdapter.getItem(position);
                if (object != null && delegate != null) {
                    delegate.didSelectLocation(object);
                }
                finishFragment();
            }
        });

        if (googleMap != null) {
            userLocation = new Location("network");
            userLocation.setLatitude(20.659322);
            userLocation.setLongitude(-11.406250);
        }

        frameLayout.addView(actionBar);
    }

    if (googleMap != null) {
        try {
            googleMap.setMyLocationEnabled(true);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        googleMap.getUiSettings().setMyLocationButtonEnabled(false);
        googleMap.getUiSettings().setZoomControlsEnabled(false);
        googleMap.getUiSettings().setCompassEnabled(false);
        googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
            @Override
            public void onMyLocationChange(Location location) {
                positionMarker(location);
            }
        });
        positionMarker(myLocation = getLastLocation());
    }

    return fragmentView;
}

From source file:com.wellsandwhistles.android.redditsp.fragments.CommentListingFragment.java

@Override
public void onCommentListingRequestPostDownloaded(final RedditPreparedPost post) {

    final Context context = getActivity();

    if (mPost == null) {

        final SRThemeAttributes attr = new SRThemeAttributes(context);

        mPost = post;/*from  w w  w  . j ava 2  s .c  o  m*/
        isArchived = post.isArchived;

        final RedditPostHeaderView postHeader = new RedditPostHeaderView(getActivity(), this.mPost);

        mCommentListingManager.addPostHeader(postHeader);
        ((LinearLayoutManager) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(0, 0);

        if (post.src.getSelfText() != null) {
            final ViewGroup selfText = post.src.getSelfText().buildView(getActivity(), attr.srMainTextCol,
                    14f * mCommentFontScale, mShowLinkButtons);
            selfText.setFocusable(false);
            selfText.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

            final int paddingPx = General.dpToPixels(context, 10);
            final FrameLayout paddingLayout = new FrameLayout(context);
            final TextView collapsedView = new TextView(context);
            collapsedView.setText("[ + ]  " + getActivity().getString(R.string.collapsed_self_post));
            collapsedView.setVisibility(View.GONE);
            collapsedView.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);
            paddingLayout.addView(selfText);
            paddingLayout.addView(collapsedView);
            paddingLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);

            paddingLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (selfText.getVisibility() == View.GONE) {
                        selfText.setVisibility(View.VISIBLE);
                        collapsedView.setVisibility(View.GONE);
                    } else {
                        selfText.setVisibility(View.GONE);
                        collapsedView.setVisibility(View.VISIBLE);
                    }

                }
            });
            // TODO mListHeaderNotifications.setBackgroundColor(Color.argb(35, 128, 128, 128));

            mCommentListingManager.addPostSelfText(paddingLayout);
        }

        if (!General.isTablet(context, PreferenceManager.getDefaultSharedPreferences(context))) {
            getActivity().setTitle(post.src.getTitle());
        }

        if (mCommentListingManager.isSearchListing()) {
            final CommentSubThreadView searchCommentThreadView = new CommentSubThreadView(getActivity(),
                    mAllUrls.get(0).asPostCommentListURL(), R.string.comment_header_search_thread_title);

            mCommentListingManager.addNotification(searchCommentThreadView);
        } else if (!mAllUrls.isEmpty() && mAllUrls.get(0).pathType() == RedditURLParser.POST_COMMENT_LISTING_URL
                && mAllUrls.get(0).asPostCommentListURL().commentId != null) {

            final CommentSubThreadView specificCommentThreadView = new CommentSubThreadView(getActivity(),
                    mAllUrls.get(0).asPostCommentListURL(), R.string.comment_header_specific_thread_title);

            mCommentListingManager.addNotification(specificCommentThreadView);
        }

        // TODO pref (currently 10 mins)
        if (mCachedTimestamp != null && SRTime.since(mCachedTimestamp) > 10 * 60 * 1000) {

            final TextView cacheNotif = (TextView) LayoutInflater.from(getActivity())
                    .inflate(R.layout.cached_header, null, false);
            cacheNotif.setText(getActivity().getString(R.string.listing_cached,
                    SRTime.formatDateTime(mCachedTimestamp, getActivity())));
            mCommentListingManager.addNotification(cacheNotif);
        }
    }
}

From source file:io.flutter.embedding.android.FlutterActivity.java

/**
 * Creates a {@link FrameLayout} with an ID of {@code #FRAGMENT_CONTAINER_ID} that will contain
 * the {@link FlutterFragment} displayed by this {@code FlutterActivity}.
 * <p>//from   ww w  .j  a  va2 s . c  om
 * @return the FrameLayout container
 */
@NonNull
private View createFragmentContainer() {
    FrameLayout container = new FrameLayout(this);
    container.setId(FRAGMENT_CONTAINER_ID);
    container.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    return container;
}

From source file:com.mobicage.rogerthat.ServiceBoundActivity.java

protected View wrapViewWithFab(View view) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH || !showFABMenu())
        return view;

    FrameLayout frameLayout = new FrameLayout(this);
    frameLayout.setLayoutParams(//from w  w w. j  a  va 2s  .c om
            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    frameLayout.addView(view);

    mFAB = new FloatingActionButton(this);
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = getFabGravity();
    int m = UIUtils.convertDipToPixels(this, 16);
    layoutParams.setMargins(m, m, m, m);
    mFAB.setLayoutParams(layoutParams);
    mFAB.setImageResource(R.drawable.ic_menu);
    mFAB.setColorNormalResId(R.color.mc_homescreen_background);
    mFAB.setColorPressedResId(R.color.mc_homescreen_background);
    mFAB.setColorRipple(R.color.mc_homescreen_background);
    mFAB.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            openOptionsMenu();
        }
    });
    mFAB.setVisibility(View.VISIBLE);
    frameLayout.addView(mFAB);
    return frameLayout;
}