Example usage for android.widget FrameLayout addView

List of usage examples for android.widget FrameLayout addView

Introduction

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

Prototype

public void addView(View child, int index) 

Source Link

Document

Adds a child view.

Usage

From source file:com.android.calculator2.Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();
    FrameLayout root = new FrameLayout(context);

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);/*from w  w  w  .  j a  va  2 s  . c o  m*/

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_VIEW_CONTAINER_ID);

    View cv = inflateView(savedInstanceState);
    cv.setId(android.R.id.content);
    lframe.addView(cv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    return root;
}

From source file:de.vanita5.twittnuker.fragment.support.DirectMessagesConversationFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_messages_conversation, null);
    final FrameLayout listContainer = (FrameLayout) view.findViewById(R.id.list_container);
    final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    listContainer.addView(super.onCreateView(inflater, container, savedInstanceState), lp);
    final ViewGroup inputSendContainer = (ViewGroup) view.findViewById(R.id.input_send_container);
    final FragmentActivity activity = getActivity();
    final int themeRes;
    if (activity instanceof IThemedActivity) {
        themeRes = ((IThemedActivity) activity).getThemeResourceId();
    } else {/*from  www . ja  v  a2s .c o  m*/
        themeRes = ThemeUtils.getThemeResource(activity);
    }
    ViewAccessor.setBackground(inputSendContainer, ThemeUtils.getActionBarSplitBackground(activity, themeRes));
    final Context actionBarContext = ThemeUtils.getActionBarContext(activity);
    View.inflate(actionBarContext, R.layout.fragment_messages_conversation_input_send, inputSendContainer);
    return view;
}

From source file:org.telegram.ui.BlockedUsersActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override/*from   w ww .j a v  a 2  s.com*/
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == block_user) {
                Bundle args = new Bundle();
                args.putBoolean("onlyUsers", true);
                args.putBoolean("destroyAfterSelect", true);
                args.putBoolean("returnAsResult", true);
                ContactsActivity fragment = new ContactsActivity(args);
                fragment.setDelegate(BlockedUsersActivity.this);
                presentFragment(fragment);
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    menu.addItem(block_user, R.drawable.plus);

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    emptyTextView = new TextView(context);
    emptyTextView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text));
    emptyTextView.setTextSize(20);
    emptyTextView.setGravity(Gravity.CENTER);
    emptyTextView.setVisibility(View.INVISIBLE);
    emptyTextView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
    frameLayout.addView(emptyTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
    emptyTextView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    progressView = new FrameLayout(context);
    frameLayout.addView(progressView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    ProgressBar progressBar = new ProgressBar(context);
    progressView.addView(progressBar,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

    listView = new ListView(context);
    listView.setEmptyView(emptyTextView);
    listView.setVerticalScrollBarEnabled(false);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setAdapter(listViewAdapter = new ListAdapter(context));
    listView.setVerticalScrollbarPosition(
            LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (i < MessagesController.getInstance().blockedUsers.size()) {
                Bundle args = new Bundle();
                args.putInt("user_id", MessagesController.getInstance().blockedUsers.get(i));
                presentFragment(new ProfileActivity(args));
            }
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (i < 0 || i >= MessagesController.getInstance().blockedUsers.size()
                    || getParentActivity() == null) {
                return true;
            }
            selectedUserId = MessagesController.getInstance().blockedUsers.get(i);

            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            CharSequence[] items = new CharSequence[] {
                    LocaleController.getString("Unblock", R.string.Unblock) };
            builder.setItems(items, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (i == 0) {
                        MessagesController.getInstance().unblockUser(selectedUserId);
                    }
                }
            });
            showDialog(builder.create());

            return true;
        }
    });

    if (MessagesController.getInstance().loadingBlockedUsers) {
        progressView.setVisibility(View.VISIBLE);
        emptyTextView.setVisibility(View.GONE);
        listView.setEmptyView(null);
    } else {
        progressView.setVisibility(View.GONE);
        listView.setEmptyView(emptyTextView);
    }
    return fragmentView;
}

From source file:pl.reticular.br.SimulationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.simulation_layout);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_simulation);
    setSupportActionBar(toolbar);/*from  w  w  w.j  a  v  a  2 s  .  c o  m*/

    FrameLayout frameLayout = (FrameLayout) findViewById(R.id.simulation_container);

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER);

    PrefsHelper.getInstance().init(this);

    Simulation simulation;

    Simulation oldSimulation = PrefsHelper.getInstance().loadOldSimulation();
    if (oldSimulation != null) {
        simulation = oldSimulation;
    } else {
        simulation = createNewSimulation();
    }

    simulationView = new SimulationView(this, simulation);

    if (frameLayout != null) {
        frameLayout.addView(simulationView, params);
    }

    setLineWidth(PrefsHelper.getInstance().getLineWidth());
}

From source file:net.bluehack.ui.WallpapersActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("ChatBackground", R.string.ChatBackground));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override// w ww.  ja va 2 s. c om
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                boolean done;
                TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
                if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) {
                    int width = AndroidUtilities.displaySize.x;
                    int height = AndroidUtilities.displaySize.y;
                    if (width > height) {
                        int temp = width;
                        width = height;
                        height = temp;
                    }
                    TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes,
                            Math.min(width, height));
                    String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
                    File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE),
                            fileName);
                    File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
                    try {
                        done = AndroidUtilities.copyFile(f, toFile);
                    } catch (Exception e) {
                        done = false;
                        FileLog.e("tmessages", e);
                    }
                } else {
                    if (selectedBackground == -1) {
                        File fromFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper-temp.jpg");
                        File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
                        done = fromFile.renameTo(toFile);
                    } else {
                        done = true;
                    }
                }

                if (done) {
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putInt("selectedBackground", selectedBackground);
                    editor.putInt("selectedColor", selectedColor);
                    editor.commit();
                    ApplicationLoader.reloadWallpaper();
                }
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    FrameLayout frameLayout = new FrameLayout(context);
    fragmentView = frameLayout;

    backgroundImage = new ImageView(context);
    backgroundImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
    frameLayout.addView(backgroundImage,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    backgroundImage.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    progressView = new FrameLayout(context);
    progressView.setVisibility(View.INVISIBLE);
    frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 52));

    progressViewBackground = new View(context);
    progressViewBackground.setBackgroundResource(R.drawable.system_loader);
    progressView.addView(progressViewBackground, LayoutHelper.createFrame(36, 36, Gravity.CENTER));

    ProgressBar progressBar = new ProgressBar(context);
    try {
        progressBar.setIndeterminateDrawable(context.getResources().getDrawable(R.drawable.loading_animation));
    } catch (Exception e) {
        //don't promt
    }
    progressBar.setIndeterminate(true);
    AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500);
    progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));

    RecyclerListView listView = new RecyclerListView(context);
    listView.setClipToPadding(false);
    listView.setTag(8);
    listView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0);
    LinearLayoutManager layoutManager = new LinearLayoutManager(context);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    listView.setLayoutManager(layoutManager);
    listView.setDisallowInterceptTouchEvents(true);
    listView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
    listView.setAdapter(listAdapter = new ListAdapter(context));
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 102, Gravity.LEFT | Gravity.BOTTOM));
    listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (position == 0) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

                CharSequence[] items = new CharSequence[] {
                        LocaleController.getString("FromCamera", R.string.FromCamera),
                        LocaleController.getString("FromGalley", R.string.FromGalley),
                        LocaleController.getString("Cancel", R.string.Cancel) };

                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        try {
                            if (i == 0) {
                                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                File image = AndroidUtilities.generatePicturePath();
                                if (image != null) {
                                    if (Build.VERSION.SDK_INT >= 24) {
                                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                                FileProvider.getUriForFile(getParentActivity(),
                                                        BuildConfig.APPLICATION_ID + ".provider", image));
                                        takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                                        takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                    } else {
                                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                                Uri.fromFile(image));
                                    }
                                    currentPicturePath = image.getAbsolutePath();
                                }
                                startActivityForResult(takePictureIntent, 10);
                            } else if (i == 1) {
                                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                                photoPickerIntent.setType("image/*");
                                startActivityForResult(photoPickerIntent, 11);
                            }
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                    }
                });
                showDialog(builder.create());
            } else {
                if (position - 1 < 0 || position - 1 >= wallPapers.size()) {
                    return;
                }
                TLRPC.WallPaper wallPaper = wallPapers.get(position - 1);
                selectedBackground = wallPaper.id;
                listAdapter.notifyDataSetChanged();
                processSelectedBackground();
            }
        }
    });

    processSelectedBackground();

    return fragmentView;
}

From source file:org.iransoil.collect.android.activities.GeoPointMapActivitySdk7.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        mLocationCount = savedInstanceState.getInt(LOCATION_COUNT);
    }/* ww w .j  a  v a  2s .co  m*/

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.geopoint_layout_sdk7);

    Intent intent = getIntent();

    mLocationAccuracy = GeoPointWidget.DEFAULT_LOCATION_ACCURACY;
    if (intent != null && intent.getExtras() != null) {
        if (intent.hasExtra(GeoPointWidget.LOCATION)) {
            double[] location = intent.getDoubleArrayExtra(GeoPointWidget.LOCATION);
            mGeoPoint = new GeoPoint((int) (location[0] * 1E6), (int) (location[1] * 1E6));
        }
        if (intent.hasExtra(GeoPointWidget.ACCURACY_THRESHOLD)) {
            mLocationAccuracy = intent.getDoubleExtra(GeoPointWidget.ACCURACY_THRESHOLD,
                    GeoPointWidget.DEFAULT_LOCATION_ACCURACY);
        }
        mCaptureLocation = !intent.getBooleanExtra(GeoPointWidget.READ_ONLY, false);
    }

    /**
     * Add the MapView dynamically to the placeholding frame so as to not
     * incur the wrath of Android Lint...
     */
    FrameLayout frame = (FrameLayout) findViewById(R.id.mapview_placeholder);
    String apiKey = "017Xo9E6R7WmcCITvo-lU2V0ERblKPqCcguwxSQ";
    // String apiKey = "0wsgFhRvVBLVpgaFzmwaYuqfU898z_2YtlKSlkg";
    mMapView = new MapView(this, apiKey);
    mMapView.setClickable(true);
    mMapView.setId(R.id.mapview);
    LayoutParams p = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    frame.addView(mMapView, p);

    mCancelLocation = (Button) findViewById(R.id.cancel_location);
    mCancelLocation.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "cancelLocation", "cancel");
            finish();
        }
    });

    mMapController = mMapView.getController();
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    mMapView.setBuiltInZoomControls(true);
    mMapView.setSatellite(false);
    mMapController.setZoom(16);

    // make sure we have a good location provider before continuing
    List<String> providers = mLocationManager.getProviders(true);
    for (String provider : providers) {
        if (provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER)) {
            mGPSOn = true;
        }
        if (provider.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)) {
            mNetworkOn = true;
        }
    }
    if (!mGPSOn && !mNetworkOn) {
        Toast.makeText(getBaseContext(), getString(R.string.provider_disabled_error), Toast.LENGTH_SHORT)
                .show();
        finish();
    }

    if (mGPSOn) {
        Location loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (loc != null) {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(GPS) lat: " + loc.getLatitude() + " long: " + loc.getLongitude()
                    + " acc: " + loc.getAccuracy());
        } else {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(GPS) null location");
        }
    }

    if (mNetworkOn) {
        if (ActivityCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(this,
                        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        Location loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (loc != null) {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(Network) lat: " + loc.getLatitude() + " long: " + loc.getLongitude()
                    + " acc: " + loc.getAccuracy());
        } else {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(Network) null location");
        }
    }

    mLocationOverlay = new MyLocationOverlay(this, mMapView);
    mMapView.getOverlays().add(mLocationOverlay);

    if (mCaptureLocation) {
        mLocationStatus = (TextView) findViewById(R.id.location_status);
        mAcceptLocation = (Button) findViewById(R.id.accept_location);
        mAcceptLocation.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "acceptLocation", "OK");
                returnLocation();
            }
        });

    } else {

        mGeoPointOverlay = new Marker(mGeoPoint);
        mMapView.getOverlays().add(mGeoPointOverlay);

        ((Button) findViewById(R.id.accept_location)).setVisibility(View.GONE);
        ((TextView) findViewById(R.id.location_status)).setVisibility(View.GONE);
        mShowLocation = ((Button) findViewById(R.id.show_location));
        mShowLocation.setVisibility(View.VISIBLE);
        mShowLocation.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "showLocation", "onClick");
                mMapController.animateTo(mGeoPoint);
            }
        });

    }

    if (mGeoPoint != null) {
        mMapController.animateTo(mGeoPoint);
    }
}

From source file:kr.wdream.ui.WallpapersActivity.java

@Override
public View createView(Context context) {
    Log.d(LOG_TAG, "createView");

    actionBar.setBackButtonImage(kr.wdream.storyshop.R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(//ww w  .j av  a2s.c  om
            LocaleController.getString("ChatBackground", kr.wdream.storyshop.R.string.ChatBackground));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                boolean done;
                TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
                if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) {
                    int width = AndroidUtilities.displaySize.x;
                    int height = AndroidUtilities.displaySize.y;
                    if (width > height) {
                        int temp = width;
                        width = height;
                        height = temp;
                    }
                    TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes,
                            Math.min(width, height));
                    String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
                    File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE),
                            fileName);
                    File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
                    try {
                        done = AndroidUtilities.copyFile(f, toFile);
                    } catch (Exception e) {
                        done = false;
                        FileLog.e("tmessages", e);
                    }
                } else {
                    if (selectedBackground == -1) {
                        File fromFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper-temp.jpg");
                        File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
                        done = fromFile.renameTo(toFile);
                    } else {
                        done = true;
                    }
                }

                if (done) {
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putInt("selectedBackground", selectedBackground);
                    editor.putInt("selectedColor", selectedColor);
                    editor.commit();
                    ApplicationLoader.reloadWallpaper();
                }
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, kr.wdream.storyshop.R.drawable.ic_done,
            AndroidUtilities.dp(56));

    FrameLayout frameLayout = new FrameLayout(context);
    fragmentView = frameLayout;

    backgroundImage = new ImageView(context);
    backgroundImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
    frameLayout.addView(backgroundImage,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    backgroundImage.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    progressView = new FrameLayout(context);
    progressView.setVisibility(View.INVISIBLE);
    frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 52));

    progressViewBackground = new View(context);
    progressViewBackground.setBackgroundResource(kr.wdream.storyshop.R.drawable.system_loader);
    progressView.addView(progressViewBackground, LayoutHelper.createFrame(36, 36, Gravity.CENTER));

    ProgressBar progressBar = new ProgressBar(context);
    try {
        progressBar.setIndeterminateDrawable(
                context.getResources().getDrawable(kr.wdream.storyshop.R.drawable.loading_animation));
    } catch (Exception e) {
        //don't promt
    }
    progressBar.setIndeterminate(true);
    AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500);
    progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));

    RecyclerListView listView = new RecyclerListView(context);
    listView.setClipToPadding(false);
    listView.setTag(8);
    listView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0);
    LinearLayoutManager layoutManager = new LinearLayoutManager(context);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    listView.setLayoutManager(layoutManager);
    listView.setDisallowInterceptTouchEvents(true);
    listView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
    listView.setAdapter(listAdapter = new ListAdapter(context));
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 102, Gravity.LEFT | Gravity.BOTTOM));
    listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (position == 0) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

                CharSequence[] items = new CharSequence[] {
                        LocaleController.getString("FromCamera", kr.wdream.storyshop.R.string.FromCamera),
                        LocaleController.getString("FromGalley", kr.wdream.storyshop.R.string.FromGalley),
                        LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel) };

                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        try {
                            if (i == 0) {
                                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                File image = AndroidUtilities.generatePicturePath();
                                if (image != null) {
                                    if (Build.VERSION.SDK_INT >= 24) {
                                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                                FileProvider.getUriForFile(getParentActivity(),
                                                        BuildConfig.APPLICATION_ID + ".provider", image));
                                        takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                                        takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                    } else {
                                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                                Uri.fromFile(image));
                                    }
                                    currentPicturePath = image.getAbsolutePath();
                                }
                                startActivityForResult(takePictureIntent, 10);
                            } else if (i == 1) {
                                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                                photoPickerIntent.setType("image/*");
                                startActivityForResult(photoPickerIntent, 11);
                            }
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                    }
                });
                showDialog(builder.create());
            } else {
                if (position - 1 < 0 || position - 1 >= wallPapers.size()) {
                    return;
                }
                TLRPC.WallPaper wallPaper = wallPapers.get(position - 1);
                selectedBackground = wallPaper.id;
                listAdapter.notifyDataSetChanged();
                processSelectedBackground();
            }
        }
    });

    processSelectedBackground();

    return fragmentView;
}

From source file:de.vanita5.twittnuker.fragment.support.BasePullToRefreshListFragment.java

/**
 * Provide default implementation to return a simple list view. Subclasses
 * can override to replace with their own layout. If doing so, the returned
 * view hierarchy <em>must</em> have a ListView whose id is
 * {@link android.R.id#list android.R.id.list} and can optionally have a
 * sibling view id {@link android.R.id#empty android.R.id.empty} that is to
 * be shown when the list is empty./*from w  ww . ja  v  a2 s . com*/
 * <p>
 * If you are overriding this method with your own custom content, consider
 * including the standard layout {@link android.R.layout#list_content} in
 * your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment. In particular, this is currently the only way
 * to have the built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final Context context = getActivity();

    final FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    final LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    final ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    final FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    final TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    final RefreshNowListView lv = new RefreshNowListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setOverScrollMode(View.OVER_SCROLL_NEVER);
    lv.setDrawSelectorOnTop(false);
    lv.setOnRefreshListener(this);
    lv.setConfig(ThemeUtils.buildRefreshNowConfig(context));
    lv.setOnTouchListener(this);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    final RefreshNowProgressIndicator indicator = new RefreshNowProgressIndicator(context);
    indicator.setConfig(ThemeUtils.buildRefreshIndicatorConfig(context));
    final int indicatorHeight = Math.round(3 * getResources().getDisplayMetrics().density);
    lframe.addView(indicator,
            new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, indicatorHeight, Gravity.TOP));

    lv.setRefreshIndicatorView(indicator);

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:com.google.blockly.android.AbstractBlocklyActivity.java

/**
 * Creates or loads the root content view (by default, {@link R.layout#drawers_and_action_bar})
 * for the Activity.  It is also responsible for assigning {@link #mActionBar} and
 * {@link #mDrawerLayout}, and adding the view returned by {@link #onCreateContentView}.
 *///from  w w  w .j a va  2 s.co m
protected void onCreateActivityRootView() {
    setContentView(R.layout.drawers_and_action_bar);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    mActionBar = getSupportActionBar();
    mActionBar.setDisplayShowTitleEnabled(true);

    // Create and attach content view into content container.  If content is a fragment, content
    // will be null here and the container will be populated during the FragmentTransaction.
    View content = onCreateContentView(R.id.content_container);
    if (content != null) {
        FrameLayout contentContainer = (FrameLayout) findViewById(R.id.content_container);
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        if (content.getParent() != contentContainer) {
            contentContainer.addView(content, lp);
        } else {
            content.setLayoutParams(lp);
        }
    }

    mNavigationDrawer = onCreateAppNavigationDrawer();
    if (mNavigationDrawer != null) {
        setupAppNaviagtionDrawer();
    }
}

From source file:org.telegram.ui.ArchivedStickersActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (currentType == StickersQuery.TYPE_IMAGE) {
        actionBar.setTitle(LocaleController.getString("ArchivedStickers", R.string.ArchivedStickers));
    } else {//from w w  w  .  j av a2 s  .  c  om
        actionBar.setTitle(LocaleController.getString("ArchivedMasks", R.string.ArchivedMasks));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    listAdapter = new ListAdapter(context);

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));

    emptyView = new EmptyTextProgressView(context);
    if (currentType == StickersQuery.TYPE_IMAGE) {
        emptyView.setText(LocaleController.getString("ArchivedStickersEmpty", R.string.ArchivedStickersEmpty));
    } else {
        emptyView.setText(LocaleController.getString("ArchivedMasksEmpty", R.string.ArchivedMasksEmpty));
    }
    frameLayout.addView(emptyView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    if (loadingStickers) {
        emptyView.showProgress();
    } else {
        emptyView.showTextView();
    }

    RecyclerListView listView = new RecyclerListView(context);
    listView.setFocusable(true);
    listView.setEmptyView(emptyView);
    listView.setLayoutManager(
            layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));

    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(final View view, int position) {
            if (position >= stickersStartRow && position < stickersEndRow && getParentActivity() != null) {
                final TLRPC.StickerSetCovered stickerSet = sets.get(position);
                TLRPC.InputStickerSet inputStickerSet;
                if (stickerSet.set.id != 0) {
                    inputStickerSet = new TLRPC.TL_inputStickerSetID();
                    inputStickerSet.id = stickerSet.set.id;
                } else {
                    inputStickerSet = new TLRPC.TL_inputStickerSetShortName();
                    inputStickerSet.short_name = stickerSet.set.short_name;
                }
                inputStickerSet.access_hash = stickerSet.set.access_hash;
                StickersAlert stickersAlert = new StickersAlert(getParentActivity(),
                        ArchivedStickersActivity.this, inputStickerSet, null, null);
                stickersAlert.setInstallDelegate(new StickersAlert.StickersAlertInstallDelegate() {
                    @Override
                    public void onStickerSetInstalled() {
                        ArchivedStickerSetCell cell = (ArchivedStickerSetCell) view;
                        cell.setChecked(true);
                    }

                    @Override
                    public void onStickerSetUninstalled() {
                        ArchivedStickerSetCell cell = (ArchivedStickerSetCell) view;
                        cell.setChecked(false);
                    }
                });
                showDialog(stickersAlert);
            }
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (!loadingStickers && !endReached
                    && layoutManager.findLastVisibleItemPosition() > stickersLoadingRow - 2) {
                getStickers();
            }
        }
    });

    return fragmentView;
}