Skip to content
Browse files

Modification of some code

  • Loading branch information...
0 parents commit 3ccac26c70b3efed9823c2f3d4b355eb79215610 @lbdremy committed Mar 15, 2011
7 .classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
33 .project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>com_markupartist_android_widget_actionbar</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
9 AndroidManifest.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.markupartist.android.widget.actionbar"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ </application>
+ <uses-sdk android:minSdkVersion="3"/>
+</manifest>
12 default.properties
@@ -0,0 +1,12 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+android.library=true
+# Project target.
+target=android-3
22 res/drawable/actionbar_background.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 Johan Nilsson <http://markupartist.com>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <gradient
+ android:startColor="@color/actionbar_background_start"
+ android:endColor="@color/actionbar_background_end"
+ android:angle="-90" />
+</shape>
51 res/drawable/actionbar_btn.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 Johan Nilsson <http://markupartist.com>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <!-- Non focused states -->
+ <item
+ android:state_focused="false"
+ android:state_selected="false"
+ android:state_pressed="false"
+ android:drawable="@drawable/actionbar_btn_normal"
+ />
+ <item
+ android:state_focused="false"
+ android:state_selected="true"
+ android:state_pressed="false"
+ android:drawable="@drawable/actionbar_btn_pressed"
+ />
+
+ <!-- Focused states -->
+ <item
+ android:state_focused="true"
+ android:state_selected="false"
+ android:state_pressed="false"
+ android:drawable="@drawable/actionbar_btn_pressed"
+ />
+ <item
+ android:state_focused="true"
+ android:state_selected="true"
+ android:state_pressed="false"
+ android:drawable="@drawable/actionbar_btn_pressed"
+ />
+
+ <!-- Pressed -->
+ <item
+ android:state_pressed="true"
+ android:drawable="@drawable/actionbar_btn_pressed"
+ />
+</selector>
22 res/drawable/actionbar_btn_normal.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 Johan Nilsson <http://markupartist.com>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <gradient
+ android:startColor="@color/actionbar_background_start"
+ android:endColor="@color/actionbar_background_end"
+ android:angle="-90"/>
+</shape>
22 res/drawable/actionbar_btn_pressed.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 Johan Nilsson <http://markupartist.com>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <gradient
+ android:startColor="@color/actionbar_background_item_pressed_start"
+ android:endColor="@color/actionbar_background_item_pressed_end"
+ android:angle="-90"/>
+</shape>
BIN res/drawable/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 res/layout/actionbar.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 Johan Nilsson <http://markupartist.com>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/screen"
+ android:layout_width="fill_parent"
+ android:layout_height="45dip"
+ android:orientation="horizontal"
+ android:background="@drawable/actionbar_background"
+ >
+ <RelativeLayout
+ android:id="@+id/actionbar_home"
+ android:layout_width="wrap_content"
+ android:layout_height="45dip"
+ android:orientation="horizontal"
+ android:layout_alignParentLeft="true"
+ android:layout_centerVertical="true"
+ android:visibility="visible"
+ >
+ <ImageView
+ android:id="@+id/actionbar_home_logo"
+ android:layout_width="wrap_content"
+ android:layout_height="45dip"
+ android:background="@drawable/actionbar_btn"
+ android:paddingLeft="5sp"
+ android:visibility="gone"
+ />
+ <RelativeLayout
+ android:id="@+id/actionbar_home_bg"
+ android:layout_width="wrap_content"
+ android:layout_height="45dip"
+ android:orientation="horizontal"
+ android:layout_alignParentLeft="true"
+ android:layout_centerVertical="true"
+ android:background="@color/actionbar_separator"
+ android:visibility="gone"
+ >
+ <!-- TODO: Make configurable. -->
+ <ImageButton
+ android:id="@+id/actionbar_home_btn"
+ android:layout_width="45dip"
+ android:layout_height="45dip"
+ android:background="@drawable/actionbar_btn"
+ android:padding="5dip"
+ android:layout_marginRight="1px"
+ />
+ </RelativeLayout>
+
+ <LinearLayout
+ android:id="@+id/actionbar_actions"
+ android:layout_width="wrap_content"
+ android:layout_height="45dip"
+ android:layout_alignParentRight="true"
+ android:layout_centerVertical="true"
+ android:background="@color/actionbar_separator"
+ >
+ </LinearLayout>
+
+ <com.markupartist.android.widget.ScrollingTextView
+ android:id="@+id/actionbar_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toRightOf="@id/actionbar_home_bg"
+ android:layout_toLeftOf="@id/actionbar_actions"
+ android:layout_alignWithParentIfMissing="true"
+ android:layout_centerVertical="true"
+ android:paddingLeft="10dip"
+ android:paddingRight="10dip"
+ android:textSize="16dip"
+ android:textStyle="bold"
+ android:textColor="@color/actionbar_title"
+ android:lines="1"
+ android:scrollHorizontally="true"
+ android:ellipsize="marquee"
+ android:marqueeRepeatLimit="marquee_forever"
+ />
+ </RelativeLayout>
+</RelativeLayout>
26 res/layout/actionbar_item.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 Johan Nilsson <http://markupartist.com>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/actionbar_item"
+ android:layout_width="@dimen/actionbar_item_width"
+ android:layout_height="@dimen/actionbar_item_height"
+ android:background="@drawable/actionbar_btn"
+ android:padding="5dip"
+ android:layout_marginLeft="1px"
+ android:layout_centerVertical="true"
+ android:singleLine="true"
+ android:visibility="visible"
+ />
21 res/values/attrs.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 Johan Nilsson <http://markupartist.com>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <declare-styleable name="ActionBar">
+ <attr name="title" format="string" localization="suggested" />
+ </declare-styleable>
+</resources>
23 res/values/colors.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 Johan Nilsson <http://markupartist.com>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <color name="actionbar_separator">#8B1A1A</color>
+ <color name="actionbar_title">#FFFFFF</color>
+ <color name="actionbar_background_start">#8B1A1A</color>
+ <color name="actionbar_background_end">#CD2626</color>
+ <color name="actionbar_background_item_pressed_start">#FF7F00</color>
+ <color name="actionbar_background_item_pressed_end">#EE7600</color>
+</resources>
20 res/values/dimens.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 Johan Nilsson <http://markupartist.com>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <dimen name="actionbar_height">45dip</dimen>
+ <dimen name="actionbar_item_height">45dip</dimen>
+ <dimen name="actionbar_item_width">45dip</dimen>
+</resources>
6 res/values/strings.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Hello World!</string>
+ <string name="app_name">ActionBar</string>
+ <string name="actionbar_activity_not_found">Failed to open intent...</string>
+</resources>
23 res/values/styles.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 Johan Nilsson <http://markupartist.com>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <style name="ActionBar">
+ <item name="android:layout_width">fill_parent</item>
+ <item name="android:layout_height">@dimen/actionbar_height</item>
+ <item name="android:orientation">horizontal</item>
+ <item name="android:background">@drawable/actionbar_background</item>
+ </style>
+</resources>
6 src/com/markupartist/android/widget/Action.java
@@ -0,0 +1,6 @@
+package com.markupartist.android.widget;
+
+public interface Action {
+ public int getDrawable();
+ public void performAction();
+}
175 src/com/markupartist/android/widget/ActionBar.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2010 Johan Nilsson <http://markupartist.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.markupartist.android.widget;
+
+import java.util.LinkedList;
+
+import com.markupartist.android.widget.actionbar.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+public class ActionBar extends RelativeLayout implements OnClickListener {
+
+ private LayoutInflater mInflater;
+ private RelativeLayout mBarView;
+ private ImageView mLogoView;
+ //private View mHomeView;
+ private TextView mTitleView;
+ private LinearLayout mActionsView;
+ private ImageButton mHomeBtn;
+ private RelativeLayout mHomeLayout;
+
+ public ActionBar(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+ mBarView = (RelativeLayout) mInflater.inflate(R.layout.actionbar, null);
+ addView(mBarView);
+
+ mLogoView = (ImageView) mBarView.findViewById(R.id.actionbar_home_logo);
+ mHomeLayout = (RelativeLayout) mBarView.findViewById(R.id.actionbar_home_bg);
+ mHomeBtn = (ImageButton) mBarView.findViewById(R.id.actionbar_home_btn);
+
+ mTitleView = (TextView) mBarView.findViewById(R.id.actionbar_title);
+ mActionsView = (LinearLayout) mBarView.findViewById(R.id.actionbar_actions);
+
+ TypedArray a = context.obtainStyledAttributes(attrs,
+ R.styleable.ActionBar);
+ CharSequence title = a.getString(R.styleable.ActionBar_title);
+ if (title != null) {
+ setTitle(title);
+ }
+ a.recycle();
+ }
+
+ public void setHomeAction(Action action) {
+ mHomeBtn.setOnClickListener(this);
+ mHomeBtn.setTag(action);
+ mHomeBtn.setImageResource(action.getDrawable());
+ mHomeLayout.setVisibility(View.VISIBLE);
+ }
+
+ /**
+ * Shows the provided logo to the left in the action bar.
+ *
+ * This is ment to be used instead of the setHomeAction and does not draw
+ * a divider to the left of the provided logo.
+ *
+ * @param resId The drawable resource id
+ */
+ public void setHomeLogo(Action action) {
+ // TODO: Add possibility to add an IntentAction as well.
+ mLogoView.setImageResource(action.getDrawable());
+ mLogoView.setOnClickListener(this);
+ mLogoView.setTag(action);
+ mLogoView.setVisibility(View.VISIBLE);
+ mHomeLayout.setVisibility(View.GONE);
+ }
+
+ public void setTitle(CharSequence title) {
+ mTitleView.setText(title);
+ }
+
+ public void setTitle(int resid) {
+ mTitleView.setText(resid);
+ }
+
+ @Override
+ public void onClick(View view) {
+ final Object tag = view.getTag();
+ if (tag instanceof Action) {
+ final Action action = (Action) tag;
+ action.performAction();
+ }
+ }
+
+ /**
+ * Adds a list of {@link Action}s.
+ * @param actionList the actions to add
+ */
+ public void addActions(ActionList actionList) {
+ int actions = actionList.size();
+ for (int i = 0; i < actions; i++) {
+ addAction(actionList.get(i));
+ }
+ }
+
+ /**
+ * Adds a new {@link Action}.
+ * @param action the action to add
+ */
+ public void addAction(Action action) {
+ final int index = mActionsView.getChildCount();
+ addAction(action, index);
+ }
+
+ /**
+ * Adds a new {@link Action} at the specified index.
+ * @param action the action to add
+ * @param index the position at which to add the action
+ */
+ public void addAction(Action action, int index) {
+ mActionsView.addView(inflateAction(action), index);
+ }
+
+ /**
+ * Inflates a {@link View} with the given {@link Action}.
+ * @param action the action to inflate
+ * @return a view
+ */
+ private View inflateAction(Action action) {
+ View view = mInflater.inflate(R.layout.actionbar_item, mActionsView, false);
+
+ ImageButton labelView =
+ (ImageButton) view.findViewById(R.id.actionbar_item);
+ labelView.setImageResource(action.getDrawable());
+
+ view.setTag(action);
+ view.setOnClickListener(this);
+ return view;
+ }
+
+ /**
+ * A {@link LinkedList} that holds a list of {@link Action}s.
+ */
+ public static class ActionList extends LinkedList<Action> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ }
+
+ /*
+ public static abstract class SearchAction extends AbstractAction {
+ public SearchAction() {
+ super(R.drawable.actionbar_search);
+ }
+ }
+ */
+}
38 src/com/markupartist/android/widget/IntentAction.java
@@ -0,0 +1,38 @@
+package com.markupartist.android.widget;
+
+import android.content.ActivityNotFoundException;
+import android.content.Context;
+import android.content.Intent;
+import android.widget.Toast;
+
+import com.markupartist.android.widget.actionbar.R;
+
+public class IntentAction implements Action {
+ private Context mContext;
+ private Intent mIntent;
+ final private int mDrawable;
+
+ public IntentAction(Context context, Intent intent, int drawable) {
+ mDrawable = drawable;
+ mContext = context;
+ mIntent = intent;
+ }
+
+ @Override
+ public int getDrawable() {
+ return mDrawable;
+ }
+
+ @Override
+ public void performAction() {
+ try {
+ if(mIntent != null){
+ mContext.startActivity(mIntent);
+ }
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(mContext,
+ mContext.getText(R.string.actionbar_activity_not_found),
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+}
51 src/com/markupartist/android/widget/ScrollingTextView.java
@@ -0,0 +1,51 @@
+package com.markupartist.android.widget;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.util.AttributeSet;
+import android.widget.TextView;
+
+/**
+ * @author marco
+ * Workaround to be able to scroll text inside a TextView without it required
+ * to be focused. For some strange reason there isn't an easy way to do this
+ * natively.
+ *
+ * Original code written by Evan Cummings:
+ * http://androidbears.stellarpc.net/?p=185
+ */
+public class ScrollingTextView extends TextView {
+
+ public ScrollingTextView(Context context, AttributeSet attrs,
+ int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ public ScrollingTextView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public ScrollingTextView(Context context) {
+ super(context);
+ }
+
+ @Override
+ protected void onFocusChanged(boolean focused, int direction,
+ Rect previouslyFocusedRect) {
+ if (focused) {
+ super.onFocusChanged(focused, direction, previouslyFocusedRect);
+ }
+ }
+
+ @Override
+ public void onWindowFocusChanged(boolean focused) {
+ if (focused) {
+ super.onWindowFocusChanged(focused);
+ }
+ }
+
+ @Override
+ public boolean isFocused() {
+ return true;
+ }
+}

0 comments on commit 3ccac26

Please sign in to comment.
Something went wrong with that request. Please try again.