How to Bring my Navigation Drawer to Front? - android

I am using this circular menu for my App.
https://github.com/oguzbilgener/CircularFloatingActionMenu
It is working. But when i open my Navigation Drawer. This Menu is in the front. How can i make the Menu to go Back to the Navigation Drawer.
How Can i Bring my Navigation Drawer to Front ?
public class Home extends MainActivity implements OnClickListener
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
this.application = (Remtt) this.getApplication();
this.preferences = this.application.getPreferences();
super.onCreate(savedInstanceState);
this.checkOnCreate();
int redActionButtonSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_size);
int redActionButtonMargin = getResources().getDimensionPixelOffset(R.dimen.action_button_margin);
int redActionButtonContentSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size);
int redActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_margin);
int redActionMenuRadius = getResources().getDimensionPixelSize(R.dimen.red_action_menu_radius);
int blueSubActionButtonSize = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_size);
int blueSubActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_content_margin);
ImageView fabIconStar = new ImageView(this);
fabIconStar.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_headphones));
FloatingActionButton.LayoutParams starParams = new FloatingActionButton.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
starParams.setMargins(redActionButtonMargin, redActionButtonMargin, redActionButtonMargin, redActionButtonMargin);
fabIconStar.setLayoutParams(starParams);
FloatingActionButton.LayoutParams fabIconStarParams = new FloatingActionButton.LayoutParams(redActionButtonContentSize, redActionButtonContentSize);
fabIconStarParams.setMargins(redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin);
FloatingActionButton leftCenterButton = new FloatingActionButton.Builder(this).setContentView(fabIconStar, fabIconStarParams).setBackgroundDrawable(R.drawable.button_action_red_selector).setPosition(FloatingActionButton.POSITION_TOP_CENTER).setLayoutParams(starParams).build();
// Set up customized SubActionButtons for the right center menu
SubActionButton.Builder lCSubBuilder = new SubActionButton.Builder(this);
lCSubBuilder.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_action_blue_selector));
FrameLayout.LayoutParams blueContentParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
blueContentParams.setMargins(blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin);
lCSubBuilder.setLayoutParams(blueContentParams);
// Set custom layout params
FrameLayout.LayoutParams blueParams = new FrameLayout.LayoutParams(blueSubActionButtonSize, blueSubActionButtonSize);
lCSubBuilder.setLayoutParams(blueParams);
ImageView lcIcon1 = new ImageView(this);
ImageView lcIcon2 = new ImageView(this);
ImageView lcIcon3 = new ImageView(this);
ImageView lcIcon4 = new ImageView(this);
ImageView lcIcon5 = new ImageView(this);
ImageView lcIcon6 = new ImageView(this);
ImageView lcIcon7 = new ImageView(this);
ImageView lcIcon8 = new ImageView(this);
ImageView lcIcon9 = new ImageView(this);
lcIcon1.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon2.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon4.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon5.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_headphones));
lcIcon6.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon7.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon8.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon9.setImageDrawable(getResources().getDrawable(R.drawable.anim));
// Build another menu with custom options
FloatingActionMenu leftCenterMenu = new FloatingActionMenu.Builder(this).addSubActionView(lCSubBuilder.setContentView(lcIcon1, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon2, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon3, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon4, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon5, blueContentParams).build())
.addSubActionView(lCSubBuilder.setContentView(lcIcon6, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon7, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon8, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon9, blueContentParams).build()).setRadius(redActionMenuRadius).setStartAngle(0).setEndAngle(360).attachTo(leftCenterButton).build();
}
}
}

This is very similar to my answer here, with only minor changes to the FloatingActionButton instantiation.
The library code assumes that the Button and Menu are to appear on top of an Activity's content View, and everything therein. The addition of a container ViewGroup member in the FloatingActionButton class allows us to specify a child ViewGroup to be the parent instead. Please note that the following changes will only work if a FloatingActionButton is used with the Menu.
The additions to the FloatingActionButton class:
public class FloatingActionButton extends FrameLayout {
...
private ViewGroup containerView;
...
public FloatingActionButton(Activity activity,
LayoutParams layoutParams,
int theme,
Drawable backgroundDrawable,
int position,
View contentView,
FrameLayout.LayoutParams contentParams
// Note the addition of the following
// constructor parameter here
, ViewGroup containerView) {
...
setClickable(true);
// This line is new. The rest of the constructor is the same.
this.containerView = containerView;
attach(layoutParams);
}
...
public View getActivityContentView() {
if(containerView == null) {
return ((Activity)getContext())
.getWindow().getDecorView().findViewById(android.R.id.content);
} else {
return containerView;
}
}
public ViewGroup getContainerView() {
return containerView;
}
// The following setter is not strictly necessary, but may be of use
// if you want to toggle the Button's and Menu's z-order placement
public void setContainerView(ViewGroup containerView) {
this.containerView = containerView;
}
...
public static class Builder {
...
private ViewGroup containerView;
...
public Builder setContainerView(ViewGroup containerView) {
this.containerView = containerView;
return this;
}
public FloatingActionButton build() {
return new FloatingActionButton(activity,
layoutParams,
theme,
backgroundDrawable,
position,
contentView,
contentParams,
// New argument
containerView);
}
}
...
}
And the changes to the FloatingActionMenu class:
public class FloatingActionMenu {
...
public View getActivityContentView() {
if(mainActionView instanceof FloatingActionButton &&
((FloatingActionButton) mainActionView).getContainerView() != null) {
return ((FloatingActionButton) mainActionView).getContainerView();
} else {
return ((Activity)mainActionView.getContext())
.getWindow().getDecorView().findViewById(android.R.id.content);
}
}
...
}
Then, assuming your Activity's layout is similar to:
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
...
</android.support.v4.widget.DrawerLayout>
In your Home Activity, you would build and instantiate leftCenterButton like so:
public class Home extends Activity implements OnClickListener {
...
#Override
protected void onCreate(Bundle savedInstanceState) {
...
FrameLayout container = (FrameLayout) findViewById(R.id.container);
FloatingActionButton leftCenterButton = new FloatingActionButton.Builder(this)
.setContentView(fabIconStar, null)
.setBackgroundDrawable(R.drawable.ic_launcher)
.setPosition(FloatingActionButton.POSITION_TOP_CENTER)
.setLayoutParams(starParams)
// The new method call is added here
.setContainerView(container)
.build();
...
}
...
}

Related

TextView SetTextSize not working inside fragment

I have a Activity with TabLayout and ViewPager. I have two fixed buttons floating on top of the activity at bottom right corner. These two buttons are Plus and Minus buttons for increasing/decreasing the font sizes of the text inside the fragment. I created an Interface inside Activity and implemented it inside the fragment where I am changing the textsize of TextView.
Problem is that it does not work at the time when I click the button. When I swipe the fragment then it shows with updated textsize. Am I missing something? Is this the correct way?
Inside Activity
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.post_single);
//....
onCoachMark();
//....
}
public void onCoachMark() {
final FrameLayout overlayFramelayout = new FrameLayout(getApplicationContext());
setContentView(overlayFramelayout);
View view = getLayoutInflater().inflate(R.layout.post_single, overlayFramelayout, false);
final View overlay_view = getLayoutInflater().inflate(R.layout.zoom_overlay, overlayFramelayout, false);
final ImageView ivPlus = (ImageView) overlay_view.findViewById(R.id.ivPlus);
final ImageView ivMinus = (ImageView) overlay_view.findViewById(R.id.ivMinus);
overlayFramelayout.addView(view);
overlayFramelayout.addView(overlay_view);
ivPlus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CommonFunctions.FONT_SIZE += 3;
CommonFunctions.putMySharedPreferences(getApplicationContext(), "fontSize", String.valueOf(CommonFunctions.FONT_SIZE));
iCoachMark.onTextSizeChange();
}
});
ivMinus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CommonFunctions.FONT_SIZE -= 3;
CommonFunctions.putMySharedPreferences(getApplicationContext(), "fontSize", String.valueOf(CommonFunctions.FONT_SIZE));
iCoachMark.onTextSizeChange();
}
});
}
public interface ICoachMark {
void onTextSizeChange();
}
public void setOnCoachMark(ICoachMark iCoachMark) {
this.iCoachMark = iCoachMark;
}
Inside Fragment:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.post_content, container, false);
tvTitle = (TextView) rootView.findViewById(R.id.tvTitle);
tvDescription = (TextView) rootView.findViewById(R.id.tvDescription);
svPost = (NestedScrollView) rootView.findViewById(R.id.svPost);
String fs = CommonFunctions.getMySharedPreferences(getActivity().getApplicationContext(), "fontSize");
if (fs.matches("")) {
CommonFunctions.putMySharedPreferences(getActivity().getApplicationContext(), "fontSize", String.valueOf(CommonFunctions.FONT_SIZE));
} else {
CommonFunctions.FONT_SIZE = Integer.valueOf(fs);
tvTitle.setTextSize(CommonFunctions.FONT_SIZE);
tvDescription.setTextSize(CommonFunctions.FONT_SIZE);
}
((PostActivity) getActivity()).onTextSizeChange(new PostActivity.ICoachMark() {
#Override
public void onTextSizeChange() {
tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, CommonFunctions.FONT_SIZE);
tvDescription.setTextSize(TypedValue.COMPLEX_UNIT_SP, CommonFunctions.FONT_SIZE);
}
});
}

supply custom view for setContentView not working?

I have a custom view extending RelativeLayout (could be any other viewgroup). In this view I have several framelayouts added with addView(). No XML exists for this view! The view constructer adds everything from code.
I want to use this custom view as any other content view for an activity.
I have this fragment activity:
MyView myview;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myview = new MyView(this);
myview.getSomeContainedFrameLayoutOfView().setId(12345);
setContentView(myview);
}
Then I do this in onResume
#Override
protected void onResume() {
super.onResume();
View u = findViewById(12345); // test, returns null
u = myview.findViewById(12345); // test, also null
SomeFragment f = new SomeFragment();
FragmentManager m = getSupportFragmentManager();
FragmentTransaction ft = m.beginTransaction();
ft.replace(12345, f); // ofcourse error (no view found for id)
ft.commit();
}
Why is findViewById null? If I change setContentView() line to
setContentView(R.layout.myframelayouts);
Everything works. So somehow I suspect
setId(12345)
does something different from:
android:id="#+id/someid"
What am I missing?
Is the view returned by getSomeContainedFrameLayoutOfView() actually contained in the RelativeLayout? That is, somewhere in MyView have you called AddView(theTargetView)?
If the target view is simply a member of MyView, then the RelativeLayout, which implements findViewById unless you override it, doesn't know about the target view.
I have something like this:
public class MojLayout extends LinearLayout {
private FrameLayout lijeviFrame;
private FrameLayout glavniFrame;
private int layoutWidth;
private int panel;
private boolean glavniFrameFullScreen = false;
public MojLayout(final Context context, final float leftWeight) {
super(context);
lijeviFrame = new FrameLayout(context);
glavniFrame = new FrameLayout(context);
post(new Runnable() {
#Override
public void run() {
layoutWidth = getWidth();
panel = (int) (layoutWidth / leftWeight);
init(context);
}
});
}
private void init(Context context) {
lijeviFrame.setId(R.id.lijeviFrame); //defined in /res/values/ids.xml
glavniFrame.setId(R.id.glavniFrame);
LinearLayout container = new LinearLayout(context);
container.setOrientation(HORIZONTAL);
....
container.addView(lijeviFrame);
container.addView(glavniFrame);
addView(container);
}
In onCreate() method I tried myView.findViewbyId(R.id.lijeviFrame) -> null, without myView, same.
I don't get it

my custom View control not Redrawing in Fragment

I have created my custom view control which extends from the View control, only drawing some information in the onDraw method.
Everything works if I create the control on a regular activity layout. But if I create this control in onCreateView() of Fragment, it paints while creating and then my View "freezes". It works and resolves but is not calling onDraw(). I'm trying to call invalidate() but nothing.
Any ideas?
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.button, container, false);
mAgatButton = (agatButton) v.findViewById(R.id.agatButton1);
mAgatButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
// This not Repainted
final GraphViewSeries TahoSer = mGraphTaho.getSeries((byte)0);
mGraphTahoPos++;
TahoSer.appendData(new GraphViewData(mGraphTahoPos, 50d), true);
//This Work correct
mTahoLabel.setText(String.format(getString(R.string.button_rpm), (int)(Math.random()*1000)));
Log.d(agatButton.class.toString(),"Click Detected: "+TahoSer.size());
}
});
final Context context = getActivity().getApplicationContext();
LinearLayout graphView = (LinearLayout) v.findViewById(R.id.graph_lay_taho);
graphView.addView(mGraphTaho = getGraphView(context,"Taho"));
mTahoLabel = (TextView) v.findViewById(R.id.tahoText);
mTahoLabel.setText(String.format(getString(R.string.button_rpm), 0));
return v;
}
private GraphView getGraphView(Context context, String Name)
{
final GraphView tmpView = new LineGraphView(context,Name);
tmpView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
List<GraphViewData> initalSeriesData = new ArrayList<GraphViewData>();
for (byte i=0;i<20;i++)
initalSeriesData.add(new GraphViewData(i, 0d));
final GraphViewSeries tahoSeries = new GraphViewSeries(initalSeriesData);
((LineGraphView) tmpView).setDrawBackground(true);
tmpView.addSeries(tahoSeries);
tmpView.setViewPort(1, 20);
tmpView.setScalable(false);
tmpView.setManualYAxis(true);
tmpView.setManualYAxisBounds(100, 0);
return tmpView;
}
If I don't use Fragment everything works. What is wrong?

How can I embed a loading progress indicator in a ListActivity and Fragment

Is there a way I can embed a loading progress indicator in a ListActivity or Fragment the same way that I can call setListShown() in a ListFragment? I can use a loading dialog but I would prefer to keep things consistent as I am already using setListShown() in other ListFragments.
Thanks.
I accomplished this by writing a wrapper for the fragment class similar to ListFragment.
public class AsyncFragment extends Fragment {
static final int INTERNAL_PROGRESS_CONTAINER_ID = 0x00ff0001;
static final int INTERNAL_CONTENT_CONTAINER_ID = 0x00ff0002;
View mProgressContainer;
View mContentContainer;
boolean mContentShown = true;
public AsyncFragment() {}
#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);
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_CONTENT_CONTAINER_ID);
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;
}
public void setView(View v) {
FrameLayout lframe = (FrameLayout) getView().findViewById(INTERNAL_CONTENT_CONTAINER_ID);
lframe.addView(v, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mProgressContainer = getView().findViewById(INTERNAL_PROGRESS_CONTAINER_ID);
mContentContainer = getView().findViewById(INTERNAL_CONTENT_CONTAINER_ID);
setContentShown(false, false);
}
#Override
public void onDestroyView() {
mContentShown = false;
mProgressContainer = mContentContainer = null;
super.onDestroyView();
}
public void setContentShown(boolean shown) {
setContentShown(shown, true);
}
public void setContentShownNoAnimation(boolean shown) {
setContentShown(shown, false);
}
private void setContentShown(boolean shown, boolean animate) {
mProgressContainer = getView().findViewById(INTERNAL_PROGRESS_CONTAINER_ID);
mContentContainer = getView().findViewById(INTERNAL_CONTENT_CONTAINER_ID);
if (mContentShown == shown) {
return;
}
mContentShown = shown;
if (shown) {
if (animate) {
mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
getActivity(), android.R.anim.fade_out));
mContentContainer.startAnimation(AnimationUtils.loadAnimation(
getActivity(), android.R.anim.fade_in));
} else {
mProgressContainer.clearAnimation();
mContentContainer.clearAnimation();
}
mProgressContainer.setVisibility(View.GONE);
mContentContainer.setVisibility(View.VISIBLE);
} else {
if (animate) {
mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
getActivity(), android.R.anim.fade_in));
mContentContainer.startAnimation(AnimationUtils.loadAnimation(
getActivity(), android.R.anim.fade_out));
} else {
mProgressContainer.clearAnimation();
mContentContainer.clearAnimation();
}
mProgressContainer.setVisibility(View.VISIBLE);
mContentContainer.setVisibility(View.GONE);
}
}
I use this for fragments that I'm populating asynchronously. To use it, do not override onCreateView(). Instead, inflate your view in onStart() and call setView() with it. The fragment will start with a loading spinner. Call setContentShow(true) after you are done populating your view to remove the loading animation and show your content.

Adding View to a Custom ViewGroup

I am trying to add Views to a custom ViewGroup. The ViewGroup gets drawn, but no Views that were added to it are visible. LineView's (which extends a View) onDraw() method does not get called. What am I doing wrong?
public class TestActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ShapeView shapeView = new ShapeView(this);
shapeView.setBackgroundColor(Color.RED);
drawContainer = (RelativeLayout)findViewById(R.id.draw_container);
drawContainer.addView(shapeView);
}
}
public class ShapeView extends ViewGroup {
private LineView mLineView;
public ShapeView (Context context) {
super(context);
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(200, 200);
this.setLayoutParams(p);
mLineView = new LineView(context);
this.addView(mLineView);
}
}
I maybe wrong but should you not be adding the shapeView to your layout "main"? What is drawContainer? I can't see it being instantiated and not in the docs. I assume main contains a relative/linear layout.
Access it by:
RelativeLayout rel = (RelativeLayout) findViewById(R.id.container);
(where the id is changed to match your id)
then:
rel.addView(shapeView);

Categories

Resources