如何在后台堆栈上将片段保留在选项卡片段中的不同片段上?

时间:2015-03-26 12:58:20

标签: java android android-fragments android-fragmentactivity

enter image description here

我需要在一个标签片段中的不同片段上保留一个片段在后面的堆栈上,这样如果我解除当前片段中的按钮,我会回到前一个片段。我怎样才能做到这一点?这是我的代码:

HomeActivity.java

public class HomeActivity extends FragmentActivity{
    FragmentTabHost mTabHost;
    String mCurrentTab;
    HashMap<String, Stack<Fragment>> mStacks;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup(this,getSupportFragmentManager(), R.id.realtabcontent);

        View homeView=LayoutInflater.from(HomeActivity.this).inflate(R.layout.homeimage, null);
        mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator(homeView),TimelineFragment.class, null);
        View addView=LayoutInflater.from(HomeActivity.this).inflate(R.layout.addimage, null);
        mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator(addView),AddFragment.class, null);
    }
}

This is the first fragment:
TimelineFragment.java

public class TimelineFragment extends Fragment{
    TextView timelineTv, profileTv;
    public ArrayList<TimeLineDetailsData>myListData;
    public ListView lv_timeLine;
    public TimelineAdapter myTimelineAdapter;
    View rootView;
    Context context;
    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
        //Inflate the layout for this fragment
        View V = inflater.inflate(R.layout.timeline_profile, container, false);
        timelineTv = (TextView) V.findViewById(R.id.timelineTv);
        profileTv = (TextView) V.findViewById(R.id.profileTv);
        lv_timeLine = (ListView)V.findViewById(R.id.lv_timeLine);
        rootView=getActivity().findViewById(android.R.id.content).getRootView();
        initView();
        initiatedata();
        timelineTv.setBackgroundColor(Color.parseColor("#614d28"));
        profileTv.setBackgroundColor(Color.parseColor("#8f7f61"));
        timelineTv.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v){
                timelineTv.setBackgroundColor(Color.parseColor("#614d28"));
                profileTv.setBackgroundColor(Color.parseColor("#8f7f61"));
            }
        });
        profileTv.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v){
                timelineTv.setBackgroundColor(Color.parseColor("#8f7f61"));
                profileTv.setBackgroundColor(Color.parseColor("#614d28"));
            }
        });
        return V;
    }
    public Bitmap takeScreenshot(){
        rootView.setDrawingCacheEnabled(true);
        return rootView.getDrawingCache();
    }
    public void saveBitmap(Bitmap bitmap){
        File imagePath=new File(Environment.getExternalStorageDirectory()+"/Android/data/com.bpd.android.pay/cache/1.png");
        FileOutputStream fos;
        try{
            fos=new FileOutputStream(imagePath);
            bitmap.compress(CompressFormat.JPEG,100,fos);
            fos.flush();
            fos.close();
        }catch(FileNotFoundException e){
            Log.e("GREC",e.getMessage(),e);
        }catch(IOException e){
            Log.e("GREC",e.getMessage(),e);
        }
    }
    private void initiatedata(){
        myListData.clear();
        for(int i=1;i<=8;i++){
            TimeLineDetailsData tempObj=new TimeLineDetailsData();
            tempObj.shortDetails="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris mauris mauris, faucibus a hendrerit eget, malesuada nec diam.";
            tempObj.Profileimage="";
            tempObj.DayAgo = i+" day ago";
            tempObj.ProfileName="Rajat subhra";
            myListData.add(tempObj);
        }
    }
    private void initView(){
        myListData=new ArrayList<TimeLineDetailsData>();
        myTimelineAdapter=new TimelineAdapter(getActivity(),myListData);
        lv_timeLine.setAdapter(myTimelineAdapter);
        myTimelineAdapter.notifyDataSetChanged();
    }
    @Override
    public void onPause()
    {
        super.onPause();
        Bitmap bitmap=takeScreenshot();
        saveBitmap(bitmap);
    }
}

Here is the next fragment:
AddFragment.java

public class AddFragment extends Fragment{
    SemiCircularRadialMenu mMenu;
    private SemiCircularRadialMenuItem mStudy, mServiceTithing, mMeditation, mPurification, mSharanagati;
    ListView lv_sharanagati;
    ArrayList<SharanagatiDetails> mySharanagatiList;
    SharanagatiAdapter mySharanagatiAdapter;
    LinearLayout linAdd;
    String cacheDir=Environment.getExternalStorageDirectory()+"/Android/data/com.bpd.android.pay/cache/1.png";
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){
        //Inflate the layout for this fragment
        View V=inflater.inflate(R.layout.add_fragment,container, false);
        linAdd = (LinearLayout) V.findViewById(R.id.linAdd);
        mStudy = new SemiCircularRadialMenuItem("study", getResources().getDrawable(R.drawable.study_icon), "Study");
        mServiceTithing = new SemiCircularRadialMenuItem("servicetithing", getResources().getDrawable(R.drawable.service_tithing_icon), "Service & Tithing");
        mMeditation = new SemiCircularRadialMenuItem("meditation", getResources().getDrawable(R.drawable.meditation_icon), "Meditation");
        mPurification = new SemiCircularRadialMenuItem("purification", getResources().getDrawable(R.drawable.purification_icon), "Purification");
        mSharanagati = new SemiCircularRadialMenuItem("sharanagati", getResources().getDrawable(R.drawable.sharanagati_icon), "Sharanagati");

        mStudy.setBackgroundColor(Color.TRANSPARENT);
        mServiceTithing.setBackgroundColor(Color.TRANSPARENT);
        mMeditation.setBackgroundColor(Color.TRANSPARENT);
        mPurification.setBackgroundColor(Color.TRANSPARENT);
        mSharanagati.setBackgroundColor(Color.TRANSPARENT);

        mMenu = (SemiCircularRadialMenu)V.findViewById(R.id.radial_menu);
        mMenu.addMenuItem(mStudy.getMenuID(), mStudy);
        mMenu.addMenuItem(mServiceTithing.getMenuID(), mServiceTithing);
        mMenu.addMenuItem(mMeditation.getMenuID(), mMeditation);
        mMenu.addMenuItem(mPurification.getMenuID(), mPurification);
        mMenu.addMenuItem(mSharanagati.getMenuID(), mSharanagati);
        mMenu.setVisibility(View.VISIBLE);
        mStudy.setOnSemiCircularRadialMenuPressed(new OnSemiCircularRadialMenuPressed(){
            @Override
            public void onMenuItemPressed(){
                Toast.makeText(getActivity(),mStudy.getText(),Toast.LENGTH_LONG).show();
                mStudy.setBackgroundColor(Color.TRANSPARENT);
            }
        });
        mServiceTithing.setOnSemiCircularRadialMenuPressed(new OnSemiCircularRadialMenuPressed(){
            @Override
            public void onMenuItemPressed() {
                Toast.makeText(getActivity(), mServiceTithing.getText(), Toast.LENGTH_LONG).show();
                mServiceTithing.setBackgroundColor(Color.TRANSPARENT);
            }
        });
        mMeditation.setOnSemiCircularRadialMenuPressed(new OnSemiCircularRadialMenuPressed() {
            @Override
            public void onMenuItemPressed() {
                Toast.makeText(getActivity(), mMeditation.getText(), Toast.LENGTH_LONG).show();
                mMeditation.setBackgroundColor(Color.TRANSPARENT);
            }
        });
        mPurification.setOnSemiCircularRadialMenuPressed(new OnSemiCircularRadialMenuPressed(){
            @Override
            public void onMenuItemPressed(){
                Toast.makeText(getActivity(),mPurification.getText(),Toast.LENGTH_LONG).show();
                mPurification.setBackgroundColor(Color.TRANSPARENT);
            }
        });
        mSharanagati.setOnSemiCircularRadialMenuPressed(new OnSemiCircularRadialMenuPressed(){
            @Override
            public void onMenuItemPressed(){
                mSharanagati.setBackgroundColor(Color.TRANSPARENT);
                Intent in=new Intent(getActivity(),SharanagatiActivity.class);
                startActivity(in);
                //mMenu.dismissMenu();
            }
        });
        return V;
    }
    private void initView() {
        mySharanagatiList = new ArrayList<SharanagatiDetails>();
        mySharanagatiAdapter = new SharanagatiAdapter(getActivity(),
            mySharanagatiList);
        lv_sharanagati.setAdapter(mySharanagatiAdapter);
        mySharanagatiAdapter.notifyDataSetChanged();
    }

    private void getSharanagatiList() {
        mySharanagatiList.clear();
        for (int i = 0; i < 20; i++) {
            SharanagatiDetails tempObj = new SharanagatiDetails();
            tempObj.SharanagatiName = "Sharanagati " + i;
            mySharanagatiList.add(tempObj);
        }
    }
}

This class is used for radial menu:
SemiCircularRadialMenu.java

公共类SemiCircularRadialMenu扩展了View {

//Static Access Variables
public static final int VERTICAL_RIGHT = 0;
public static final int VERTICAL_LEFT = 1;
public static final int HORIZONTAL_TOP = 2;
public static final int HORIZONTAL_BOTTOM = 3;
//Private non-shared variables
private boolean isMenuVisible = false;
private boolean isMenuTogglePressed = false;
private boolean isMenuItemPressed = false;
private String mPressedMenuItemID = null;
private int mDiameter = 0;
private float mRadius = 0.0f;
private int mStartAngle = 0;
private RectF mMenuRect;
private RectF mMenuCenterButtonRect;
private Paint mRadialMenuPaint=new Paint(Paint.ANTI_ALIAS_FLAG);    
private Point mViewAnchorPoints;
private HashMap<String, SemiCircularRadialMenuItem> mMenuItems = new HashMap<String, SemiCircularRadialMenuItem>();
//Variables that can be user defined
private float mShadowRadius = 5 * getResources().getDisplayMetrics().density;
private boolean isShowMenuText = false;
private int mOrientation = HORIZONTAL_BOTTOM;
private int centerRadialColor = Color.WHITE;
private int mShadowColor = Color.TRANSPARENT;
private String openMenuText = "Open";
private String closeMenuText = "Close";
private String centerMenuText = openMenuText;   //Not to be set using setter method
private int mToggleMenuTextColor = Color.TRANSPARENT;
private float textSize = 12 * getResources().getDisplayMetrics().density;
private int mOpenButtonScaleFactor = 3;

public SemiCircularRadialMenu(Context context) {
    super(context);
    init();
}

public SemiCircularRadialMenu(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public SemiCircularRadialMenu(Context context, AttributeSet attrs,int defStyle) {
    super(context, attrs, defStyle);
    init();
}

private void init() {
    mRadialMenuPaint.setTextSize(textSize);
    mRadialMenuPaint.setColor(Color.TRANSPARENT);
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    mRadialMenuPaint.setShadowLayer(mShadowRadius,0.0f,0.0f,mShadowColor);
    //Draw the menu if the menu is to be displayed
    //if(isMenuVisible){
        canvas.drawArc(mMenuRect,mStartAngle,180,true,mRadialMenuPaint);
        //See if there is any item in the collection
        if(mMenuItems.size() > 0) {
            float mStart = mStartAngle;
            //Get the sweep angles based on the number of menu items
            float mSweep = 180/mMenuItems.size();
            for(SemiCircularRadialMenuItem item:mMenuItems.values()){
                mRadialMenuPaint.setColor(Color.TRANSPARENT/*item.getBackgroundColor()*/);
                item.setMenuPath(mMenuCenterButtonRect, mMenuRect, mStart, mSweep, mRadius, mViewAnchorPoints);
                canvas.drawPath(item.getMenuPath(), mRadialMenuPaint);
                //if(isShowMenuText){
                    mRadialMenuPaint.setShadowLayer(mShadowRadius, 0.0f, 0.0f, Color.TRANSPARENT);  
                    mRadialMenuPaint.setColor(Color.TRANSPARENT/*item.getTextColor()*/);
                    canvas.drawTextOnPath(item.getText(), item.getMenuPath(), 5, textSize, mRadialMenuPaint);
                    mRadialMenuPaint.setShadowLayer(mShadowRadius, 0.0f, 0.0f, Color.TRANSPARENT/*mShadowColor*/);
                //}
                item.getIcon().draw(canvas);
                mStart += mSweep;
            }
            mRadialMenuPaint.setStyle(Style.FILL);
        }
    //}
    //Draw the center menu toggle piece
    mRadialMenuPaint.setColor(centerRadialColor);
    canvas.drawArc(mMenuCenterButtonRect, mStartAngle,/*18*/0, true, mRadialMenuPaint);
    mRadialMenuPaint.setShadowLayer(mShadowRadius, 0.0f, 0.0f, Color.TRANSPARENT);  
    //Draw the center text
    drawCenterText(canvas, mRadialMenuPaint);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    int x = (int) event.getX();
    int y = (int) event.getY();

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if(mMenuCenterButtonRect.contains(x, y)) {
            centerRadialColor = RadialMenuColors.HOLO_LIGHT_BLUE;
            isMenuTogglePressed = true;
            invalidate();
        } else if(isMenuVisible) {
            if(mMenuItems.size()>0) {
                for(SemiCircularRadialMenuItem item : mMenuItems.values()) {
                    if(mMenuRect.contains((int) x, (int) y))
                        if(item.getBounds().contains((int) x, (int) y)) {
                            isMenuItemPressed = true;
                            mPressedMenuItemID = item.getMenuID();
                            break;
                        }
                }
                mMenuItems.get(mPressedMenuItemID)
                    .setBackgroundColor(Color.TRANSPARENT/*mMenuItems.get(mPressedMenuItemID).getMenuSelectedColor()*/);
                invalidate();
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        if(isMenuTogglePressed){
            centerRadialColor=Color.WHITE;
            if(isMenuVisible){
                isMenuVisible=false;
                centerMenuText=openMenuText;
            } else {
                isMenuVisible = true;
                centerMenuText = closeMenuText;
            }
            isMenuTogglePressed = false;
            invalidate();
        }

        if(isMenuItemPressed) {
            if(mMenuItems.get(mPressedMenuItemID).getCallback() != null) {
                mMenuItems.get(mPressedMenuItemID).getCallback().onMenuItemPressed();
            }
            mMenuItems.get(mPressedMenuItemID)
                .setBackgroundColor(Color.TRANSPARENT);
            isMenuItemPressed = false;
            invalidate();
        }
        break;
    }
    return true;
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    //Determine the diameter and the radius based on device orientation
    if(w > h) {
        mDiameter = h;
        mRadius = mDiameter/2 - (getPaddingTop() + getPaddingBottom());
    } else {
        mDiameter = w;
        mRadius = mDiameter/2 - (getPaddingLeft() + getPaddingRight());
    }
    //Init the draw arc Rect object
    mMenuRect = getRadialMenuRect(false);
    mMenuCenterButtonRect = getRadialMenuRect(true);
}
/**
 * Draw the toggle menu button text.
 * @param canvas
 * @param paint
 */
private void drawCenterText(Canvas canvas, Paint paint) {
    paint.setColor(mToggleMenuTextColor);
    switch(mOrientation) {
    case VERTICAL_RIGHT:
        canvas.drawText(centerMenuText, getWidth() - paint.measureText(centerMenuText), getHeight()/2, paint);
        break;
    case VERTICAL_LEFT:
        canvas.drawText(centerMenuText, 2, getHeight()/2, paint);
        break;
    case HORIZONTAL_TOP:
        canvas.drawText(centerMenuText, (getWidth()/2) - (paint.measureText(centerMenuText)/2), textSize, paint);
        break;
    case HORIZONTAL_BOTTOM:
        canvas.drawText(centerMenuText, (getWidth()/2) - (paint.measureText(centerMenuText)/2), getHeight()/2 - (textSize), paint);
        break;
    }
}

/* Get the arc drawing rects
 * @param isCenterButton
 * @return*/
private RectF getRadialMenuRect(boolean isCenterButton) {
    int left, right, top, bottom;
    left = right = top = bottom= 0;
    switch(mOrientation) {
    case VERTICAL_RIGHT:
        if(isCenterButton) {
            left = getWidth() - (int) (mRadius/mOpenButtonScaleFactor);
            right = getWidth() + (int) (mRadius/mOpenButtonScaleFactor);
            top = (getHeight()/2) - (int) (mRadius/mOpenButtonScaleFactor);
            bottom = (getHeight()/2) + (int) (mRadius/mOpenButtonScaleFactor);              
        } else {
            left = getWidth() - (int) mRadius;
            right = getWidth() + (int) mRadius;
            top = (getHeight()/2) - (int) mRadius;
            bottom = (getHeight()/2) + (int) mRadius;
        }
        mStartAngle = 90;
        mViewAnchorPoints = new Point(getWidth(), getHeight()/2);
        break;
    case VERTICAL_LEFT:
        if(isCenterButton) {
            left = -(int) (mRadius/mOpenButtonScaleFactor);
            right = (int) (mRadius/mOpenButtonScaleFactor);
            top = (getHeight()/2) - (int) (mRadius/mOpenButtonScaleFactor);
            bottom = (getHeight()/2) + (int) (mRadius/mOpenButtonScaleFactor);
        } else {
            left = -(int) mRadius;
            right = (int) mRadius;
            top = (getHeight()/2) - (int) mRadius;
            bottom = (getHeight()/2) + (int) mRadius;
        }
        mStartAngle = 270;
        mViewAnchorPoints = new Point(0, getHeight()/2);
        break;
    case HORIZONTAL_TOP:
        if(isCenterButton) {
            left = (getWidth()/2) - (int) (mRadius/mOpenButtonScaleFactor);
            right = (getWidth()/2) + (int) (mRadius/mOpenButtonScaleFactor);
            top = -(int) (mRadius/mOpenButtonScaleFactor);
            bottom = (int) (mRadius/mOpenButtonScaleFactor);
        } else {
            left = (getWidth()/2) - (int) mRadius;
            right = (getWidth()/2) + (int) mRadius;
            top = -(int) mRadius;
            bottom = (int) mRadius;
        }
        mStartAngle = 0;
        mViewAnchorPoints = new Point(getWidth()/2, 0);
        break;
    case HORIZONTAL_BOTTOM:
        if(isCenterButton) {
            left = (getWidth()/2) - (int) (mRadius/mOpenButtonScaleFactor);
            right = (getWidth()/2) + (int) (mRadius/mOpenButtonScaleFactor);
            top = getHeight() - (int) (mRadius/mOpenButtonScaleFactor);
            bottom = getHeight() + (int) (mRadius/mOpenButtonScaleFactor);
        } else {
            left = (getWidth()/2) - (int) mRadius;
            right = (getWidth()/2) + (int) mRadius;
            top = getHeight() - (int) mRadius;
            bottom = getHeight() + (int) mRadius;
        }
        mStartAngle = 180;
        mViewAnchorPoints = new Point(getWidth()/2, getHeight());
        break;
    }
    Rect rect = new Rect(left, top, right, bottom);
    Log.i(VIEW_LOG_TAG, " Top " + top + " Bottom " + bottom + " Left " + left + "  Right " + right);
    return new RectF(rect); 
}

/* Getter and setter methods*/

/**
 * Set the orientation the semi-circular radial menu.
 * There are four possible orientations only
 * VERTICAL_RIGHT , VERTICAL_LEFT , HORIZONTAL_TOP, 
 * HORIZONTAL_BOTTOM
 * @param orientation
 */
public void setOrientation(int orientation) {
    mOrientation = orientation;
    mMenuRect = getRadialMenuRect(false);
    mMenuCenterButtonRect = getRadialMenuRect(true);
    invalidate();
}
public void addMenuItem(String idTag, SemiCircularRadialMenuItem mMenuItem) {
    mMenuItems.put(idTag, mMenuItem);
    invalidate();
}
public void removeMenuItemById(String idTag) {
    mMenuItems.remove(idTag);
    invalidate();
}
public void removeAllMenuItems() {
    mMenuItems.clear();
    invalidate();
}
public void dismissMenu() {
    isMenuVisible = false;
    centerMenuText = openMenuText;
    invalidate();
}
public float getShadowRadius() {
    return mShadowRadius;
}
public void setShadowRadius(int mShadowRadius) {
    this.mShadowRadius = mShadowRadius * getResources().getDisplayMetrics().density;
    invalidate();
}
public boolean isShowMenuText() {
    return isShowMenuText;
}
public void setShowMenuText(boolean isShowMenuText) {
    this.isShowMenuText = isShowMenuText;
    invalidate();
}
public int getOrientation() {
    return mOrientation;
}
public int getCenterRadialColor() {
    return centerRadialColor;
}
public void setCenterRadialColor(int centerRadialColor) {
    this.centerRadialColor = centerRadialColor;
    invalidate();
}
public int getShadowColor() {
    return mShadowColor;
}
public void setShadowColor(int mShadowColor) {
    this.mShadowColor = mShadowColor;
    invalidate();
}
public String getOpenMenuText() {
    return openMenuText;
}
public void setOpenMenuText(String openMenuText) {
    this.openMenuText = openMenuText;
    if(!isMenuTogglePressed)
        centerMenuText = openMenuText;
    invalidate();
}
public String getCloseMenuText() {
    return closeMenuText;
}
public void setCloseMenuText(String closeMenuText) {
    this.closeMenuText = closeMenuText;
    if(isMenuTogglePressed)
        centerMenuText = closeMenuText;
    invalidate();
}
public int getToggleMenuTextColor() {
    return mToggleMenuTextColor;
}
public void setToggleMenuTextColor(int mToggleMenuTextColor) {
    this.mToggleMenuTextColor = mToggleMenuTextColor;
    invalidate();
}
public float getTextSize() {
    return textSize;
}
public void setTextSize(int textSize) {
    this.textSize = textSize  * getResources().getDisplayMetrics().density;
    mRadialMenuPaint.setTextSize(this.textSize);
    invalidate();
}
public int getOpenButtonScaleFactor() {
    return mOpenButtonScaleFactor;
}
public void setOpenButtonScaleFactor(int mOpenButtonScaleFactor) {
    this.mOpenButtonScaleFactor = mOpenButtonScaleFactor;
    invalidate();
}

}

This class is for the radial items:
SemiCircularMenuItem.java

public class SemiCircularRadialMenuItem {

    private String mMenuID;
    private Drawable mIcon;
    private String mText;
    private int mBackgroundColor;
    private int mMenuNormalColor;
    private int mMenuSelectedColor;
    private int mTextColor;
    private Path mPath;
    private RectF mBounds;
    private OnSemiCircularRadialMenuPressed mCallback;
    private int mIconDimen;

    public interface OnSemiCircularRadialMenuPressed {
        public void onMenuItemPressed();
    }
    public SemiCircularRadialMenuItem(String id, Drawable mIcon, String mText) {
        super();
        this.mMenuID = id;
        this.mIcon = mIcon;
        this.mText = mText;
        this.mMenuNormalColor = Color.WHITE;
        this.mMenuSelectedColor = Color.LTGRAY;
        this.mBackgroundColor = mMenuNormalColor;
        this.mTextColor = Color.BLACK;
        this.mIconDimen = 64;
        mPath = new Path();
        mBounds = new RectF();
    }
    public int getTextColor() {
        return mTextColor;
    }
    public void setTextColor(int mTextColor) {
        this.mTextColor = mTextColor;
    }
    public String getMenuID() {
        return mMenuID;
    }
    public int getIconDimen() {
        return mIconDimen;
    }
    public void setIconDimen(int mIconDimen) {
        this.mIconDimen = mIconDimen;
    }
    public Path getMenuPath() {
        return mPath;
    }
    public RectF getBounds() {
        return mBounds;
    }
    public void setMenuPath(RectF menuButtonRect, RectF menuRect, float StartArc, float ArcWidth, float radius, Point anchorPoint) {
        int left, right, top, bottom;
        left = right = top = bottom= 0;
        //Draw the widget path
        mPath.arcTo(menuRect, StartArc, ArcWidth);
        mPath.arcTo(menuButtonRect, StartArc + ArcWidth, -ArcWidth);
        mPath.close();
        mPath.computeBounds(mBounds, true);
        //Get the drawable bounds
        Point drawableCenter = pointOnCircle((radius - (radius/5)),StartArc + (ArcWidth/2),anchorPoint);
        left = (int) drawableCenter.x - (mIconDimen/2);
        top = (int) drawableCenter.y - (mIconDimen/2);
        right = left + (mIconDimen);
        bottom = top + (mIconDimen);
        mIcon.setBounds(left, top, right, bottom);
    }

    private Point pointOnCircle(float radius, float angleInDegrees, Point origin) {    
        int x = (int)(radius * Math.cos(angleInDegrees * Math.PI / 180F)) + origin.x;
        int y = (int)(radius * Math.sin(angleInDegrees * Math.PI / 180F)) + origin.y;
        return new Point(x, y);
    }
    public Drawable getIcon() {
        return mIcon;
    }
    public String getText() {
        return mText;
    }
    public void setOnSemiCircularRadialMenuPressed(OnSemiCircularRadialMenuPressed mCallback) {
        this.mCallback = mCallback;
    }
    public OnSemiCircularRadialMenuPressed getCallback() {
        return mCallback;
    }
    public int getBackgroundColor() {
        return mBackgroundColor;
    }   
    public void setBackgroundColor(int color) {
        this.mBackgroundColor = color;
    }
    public int getMenuNormalColor() {
        return mMenuNormalColor;
    }
    public void setMenuNormalColor(int mMenuNormalColor) {
        this.mMenuNormalColor = mMenuNormalColor;
    }
    public int getMenuSelectedColor() {
        return mMenuSelectedColor;
    }
    public void setMenuSelectedColor(int mMenuSelectedColor) {
        this.mMenuSelectedColor = mMenuSelectedColor;
    }
}


Now the XML files:

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical">
    <android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0"/>

            <FrameLayout
                android:id="@+id/realtabcontent"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
            <TabWidget
                android:id="@android:id/tabs"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"/>
        </LinearLayout>
    </android.support.v4.app.FragmentTabHost>
</LinearLayout>

This is the first fragment:
timeline_profile.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <include
        android:id="@+id/include_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/header"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/timelineTv"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="@string/timeline"
            android:background="#614d28"
            android:textColor="#FFF"
            android:textSize="@dimen/text_big"
            android:padding="@dimen/tab_padding"/>
        <TextView
            android:id="@+id/profileTv"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="@string/profile"
            android:background="#8f7f61"
            android:textColor="#FFF"
            android:textSize="@dimen/text_big"
            android:padding="@dimen/tab_padding"/>
    </LinearLayout>
    <ListView
        android:id="@+id/lv_timeLine"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dp"
        android:background="@android:color/transparent"
        android:divider="@null"
        android:dividerHeight="@dimen/paddingTopValue"
        android:layout_margin="@dimen/paddingTopValue"/>
</LinearLayout>

This is another fragment:
add_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#99000000"
    android:layout_gravity="bottom"
    android:id="@+id/linAdd">
    <com.bpd.utils.SemiCircularRadialMenu
        android:id="@+id/radial_menu"
        android:layout_width="match_parent"
        android:layout_height="360dp"
        android:padding="5dp"
        android:background="@android:color/transparent"/>
</LinearLayout>

0 个答案:

没有答案