Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'octicons' into next

GitHub doesn't want Octicons to be used outside of GitHub, so this branch
is only being merged temporarily so that I have placeholder icons to work
with.

<3 you GitHub.
  • Loading branch information...
commit 3acc64ec2fa2fca01bbd9ea36d9ad2b51ff30293 2 parents 91ef48f + 4dc7bb2
@EddieRingle authored
View
BIN  assets/octicons_regular.ttf
Binary file not shown
View
13 res/layout/repository.xml
@@ -42,6 +42,14 @@
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
+ <net.idlesoft.android.apps.github.ui.widgets.OcticonView
+ android:id="@+id/ov_repository_privacy"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical|left"
+ android:textColor="@color/light_text_color"
+ android:textSize="24dp"
+ android:layout_marginRight="5dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -60,11 +68,6 @@
android:textSize="14dp"
android:ellipsize="end" />
</LinearLayout>
- <ImageView android:id="@+id/iv_repository_privacy"
- android:layout_width="16dp"
- android:layout_height="16dp"
- android:layout_gravity="center_vertical|right"
- android:layout_marginLeft="5dp" />
</LinearLayout>
<net.idlesoft.android.apps.github.ui.widgets.IdleList android:id="@+id/lv_repository_info"
android:layout_width="match_parent"
View
24 res/layout/repository_list_item.xml
@@ -70,32 +70,32 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:gravity="right|center_vertical"
+ android:gravity="right"
android:orientation="horizontal">
<TextView android:id="@+id/tv_repository_forks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp" />
- <ImageView
- android:layout_width="16dp"
- android:layout_height="16dp"
- android:layout_gravity="bottom"
- android:src="@drawable/fork" />
+ <net.idlesoft.android.apps.github.ui.widgets.OcticonView
+ android:id="@id/octicon_fork"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:gravity="right|center_vertical"
+ android:gravity="right"
android:orientation="horizontal">
<TextView android:id="@+id/tv_repository_watchers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp" />
- <ImageView
- android:layout_width="16dp"
- android:layout_height="16dp"
- android:layout_gravity="bottom"
- android:src="@drawable/watcher" />
+ <net.idlesoft.android.apps.github.ui.widgets.OcticonView
+ android:id="@id/octicon_watchers"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
View
145 res/values/ids.xml
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (c) 2012 Eddie Ringle
+ ~ All rights reserved.
+ ~
+ ~ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
+ ~ following conditions are met:
+ ~
+ ~ Redistributions of source code must retain the above copyright notice, this list of conditions and the following
+ ~ disclaimer.
+ ~ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
+ ~ disclaimer in the documentation and/or other materials provided with the distribution.
+ ~
+ ~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ ~ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ ~ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ ~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ ~ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ ~ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ ~ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ -->
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <item type="id" name="octicon_private_repo" />
+ <item type="id" name="octicon_public_repo" />
+ <item type="id" name="octicon_repo_forked"/>
+ <item type="id" name="octicon_create"/>
+ <item type="id" name="octicon_delete"/>
+ <item type="id" name="octicon_push"/>
+ <item type="id" name="octicon_pull"/>
+ <item type="id" name="octicon_wiki"/>
+ <item type="id" name="octicon_readme"/>
+ <item type="id" name="octicon_octocat"/>
+ <item type="id" name="octicon_blacktocat"/>
+ <item type="id" name="octicon_invertocat"/>
+ <item type="id" name="octicon_download"/>
+ <item type="id" name="octicon_upload"/>
+ <item type="id" name="octicon_keyboard"/>
+ <item type="id" name="octicon_gist"/>
+ <item type="id" name="octicon_gist_private"/>
+ <item type="id" name="octicon_code_file"/>
+ <item type="id" name="octicon_download_unknown"/>
+ <item type="id" name="octicon_text_file"/>
+ <item type="id" name="octicon_download_text"/>
+ <item type="id" name="octicon_download_media"/>
+ <item type="id" name="octicon_download_zip"/>
+ <item type="id" name="octicon_download_pdf"/>
+ <item type="id" name="octicon_download_tag"/>
+ <item type="id" name="octicon_directory"/>
+ <item type="id" name="octicon_submodule"/>
+ <item type="id" name="octicon_person"/>
+ <item type="id" name="octicon_team"/>
+ <item type="id" name="octicon_member_added"/>
+ <item type="id" name="octicon_member_removed"/>
+ <item type="id" name="octicon_follow"/>
+ <item type="id" name="octicon_watching"/>
+ <item type="id" name="octicon_unwatch"/>
+ <item type="id" name="octicon_commit"/>
+ <item type="id" name="octicon_public_fork"/>
+ <item type="id" name="octicon_fork"/>
+ <item type="id" name="octicon_private_fork"/>
+ <item type="id" name="octicon_pull_request"/>
+ <item type="id" name="octicon_merge"/>
+ <item type="id" name="octicon_public_mirror"/>
+ <item type="id" name="octicon_private_mirror"/>
+ <item type="id" name="octicon_issue_opened"/>
+ <item type="id" name="octicon_issue_reopened"/>
+ <item type="id" name="octicon_issue_closed"/>
+ <item type="id" name="octicon_issue_comment"/>
+ <item type="id" name="octicon_star"/>
+ <item type="id" name="octicon_commit_comment"/>
+ <item type="id" name="octicon_help"/>
+ <item type="id" name="octicon_exclamation"/>
+ <item type="id" name="octicon_search_input"/>
+ <item type="id" name="octicon_advanced_search"/>
+ <item type="id" name="octicon_notifications" />
+ <item type="id" name="octicon_account_settings"/>
+ <item type="id" name="octicon_logout"/>
+ <item type="id" name="octicon_admin_tools"/>
+ <item type="id" name="octicon_feed"/>
+ <item type="id" name="octicon_clipboard"/><!-- Unofficial name -->
+ <item type="id" name="octicon_apple"/>
+ <item type="id" name="octicon_windows"/>
+ <item type="id" name="octicon_ios"/>
+ <item type="id" name="octicon_android"/>
+ <item type="id" name="octicon_confirm"/>
+ <item type="id" name="octicon_unread_note"/>
+ <item type="id" name="octicon_read_note"/>
+ <item type="id" name="octicon_arr_up"/>
+ <item type="id" name="octicon_arr_right"/>
+ <item type="id" name="octicon_arr_down"/>
+ <item type="id" name="octicon_arr_left"/>
+ <item type="id" name="octicon_pin"/>
+ <item type="id" name="octicon_gift"/>
+ <item type="id" name="octicon_graph"/>
+ <item type="id" name="octicon_wrench"/>
+ <item type="id" name="octicon_credit_card"/>
+ <item type="id" name="octicon_time"/>
+ <item type="id" name="octicon_ruby"/>
+ <item type="id" name="octicon_podcast"/>
+ <item type="id" name="octicon_key"/>
+ <item type="id" name="octicon_force_push"/>
+ <item type="id" name="octicon_sync"/>
+ <item type="id" name="octicon_clone"/>
+ <item type="id" name="octicon_diff"/>
+ <item type="id" name="octicon_watchers"/>
+ <item type="id" name="octicon_discussion"/>
+ <item type="id" name="octicon_delete_note"/>
+ <item type="id" name="octicon_remove_close"/>
+ <item type="id" name="octicon_reply"/>
+ <item type="id" name="octicon_mail_status"/>
+ <item type="id" name="octicon_block"/>
+ <item type="id" name="octicon_tag_create"/>
+ <item type="id" name="octicon_tag_delete"/>
+ <item type="id" name="octicon_branch_create"/>
+ <item type="id" name="octicon_branch_delete"/>
+ <item type="id" name="octicon_edit"/>
+ <item type="id" name="octicon_info"/>
+ <item type="id" name="octicon_arr_collapsed"/>
+ <item type="id" name="octicon_arr_expanded"/>
+ <item type="id" name="octicon_link"/>
+ <item type="id" name="octicon_add"/>
+ <item type="id" name="octicon_reorder"/>
+ <item type="id" name="octicon_code"/>
+ <item type="id" name="octicon_location"/>
+ <item type="id" name="octicon_u_list"/>
+ <item type="id" name="octicon_o_list"/>
+ <item type="id" name="octicon_quotemark"/>
+ <item type="id" name="octicon_version"/>
+ <item type="id" name="octicon_brightness"/>
+ <item type="id" name="octicon_fullscreen"/>
+ <item type="id" name="octicon_normalscreen"/>
+ <item type="id" name="octicon_calendar"/>
+ <item type="id" name="octicon_beer"/>
+ <item type="id" name="octicon_lock"/>
+ <item type="id" name="octicon_secure"/>
+ <item type="id" name="octicon_added"/>
+ <item type="id" name="octicon_removed"/>
+ <item type="id" name="octicon_modified"/>
+ <item type="id" name="octicon_moved"/>
+ <item type="id" name="octicon_add_comment"/>
+ <item type="id" name="octicon_horizontal_rule"/>
+ <item type="id" name="octicon_arr_right_mini"/>
+ <item type="id" name="octicon_jump_down"/>
+ <item type="id" name="octicon_jump_up"/>
+</resources>
View
14 src/net/idlesoft/android/apps/github/ui/activities/BaseActivity.java
@@ -35,14 +35,11 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
+import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
-import android.util.Log;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
@@ -52,7 +49,7 @@
import net.idlesoft.android.apps.github.R;
import net.idlesoft.android.apps.github.authenticator.AccountSelect;
import net.idlesoft.android.apps.github.ui.fragments.BaseFragment;
-import net.idlesoft.android.apps.github.ui.fragments.EventsFragment;
+import net.idlesoft.android.apps.github.ui.widgets.OcticonView;
import org.eclipse.egit.github.core.User;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.UserService;
@@ -121,6 +118,13 @@ void onCreate(final Bundle icicle, final int layout)
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
+
+ final OcticonView ov =
+ new OcticonView(getContext())
+ .setGlyphColor(Color.parseColor(getString(R.color.github_blue)))
+ .setOcticon(OcticonView.IC_INVERTOCAT)
+ .setGlyphSize(32.0f);
+ actionBar.setLogo(ov.toDrawable());
}
protected
View
22 src/net/idlesoft/android/apps/github/ui/fragments/RepositoryFragment.java
@@ -23,6 +23,7 @@
import android.accounts.AccountsException;
import android.content.Intent;
+import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -35,6 +36,7 @@
import net.idlesoft.android.apps.github.R;
import net.idlesoft.android.apps.github.ui.adapters.InfoListAdapter;
import net.idlesoft.android.apps.github.ui.widgets.IdleList;
+import net.idlesoft.android.apps.github.ui.widgets.OcticonView;
import net.idlesoft.android.apps.github.utils.RequestCache;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.User;
@@ -345,11 +347,21 @@ void buildUI(final Repository repository)
tvDescription.setVisibility(View.GONE);
}
- final ImageView ivPrivacy = (ImageView) mContent.findViewById(R.id.iv_repository_privacy);
- if (repository.isPrivate())
- ivPrivacy.setImageResource(R.drawable.lock);
- else
- ivPrivacy.setImageResource(R.drawable.open_lock);
+ final OcticonView ovPrivacy = (OcticonView) mContent.findViewById(R.id.ov_repository_privacy);
+ final boolean isFork = repository.isFork();
+ final boolean isPrivate = repository.isPrivate();
+ if (isPrivate) {
+ if (isFork)
+ ovPrivacy.setOcticon(OcticonView.IC_PRIVATE_FORK);
+ else
+ ovPrivacy.setOcticon(OcticonView.IC_PRIVATE_REPO);
+ } else {
+ if (isFork)
+ ovPrivacy.setOcticon(OcticonView.IC_PUBLIC_FORK);
+ else
+ ovPrivacy.setOcticon(OcticonView.IC_PUBLIC_REPO);
+ }
+
}
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
View
691 src/net/idlesoft/android/apps/github/ui/widgets/OcticonView.java
@@ -0,0 +1,691 @@
+package net.idlesoft.android.apps.github.ui.widgets;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Typeface;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.PaintDrawable;
+import android.text.Html;
+import android.util.AttributeSet;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+import net.idlesoft.android.apps.github.R;
+
+import static android.view.View.MeasureSpec.EXACTLY;
+import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
+
+public
+class OcticonView extends RelativeLayout
+{
+ private static final float OCTICON_CORNER_RADIUS = 3;
+ private static final String OCTICON_FONT = "octicons_regular.ttf";
+ private static Typeface OCTICON_TYPE = null;
+
+ public static final int MINI = 0xf000;
+ public static final int MEGA = 0xf200;
+
+ public static final int IC_PRIVATE_REPO = 0x0000;
+ public static final int IC_PUBLIC_REPO = 0x0001;
+ public static final int IC_REPO_FORKED = 0x0002;
+ public static final int IC_CREATE = 0x0003;
+ public static final int IC_DELETE = 0x0004;
+ public static final int IC_PUSH = 0x0005;
+ public static final int IC_PULL = 0x0006;
+ public static final int IC_WIKI = 0x0007;
+ public static final int IC_README = 0x0007;
+ public static final int IC_OCTOCAT = 0x0008;
+ public static final int IC_BLACKTOCAT = 0x0009;
+ public static final int IC_INVERTOCAT = 0x000a;
+ public static final int IC_DOWNLOAD = 0x000b;
+ public static final int IC_UPLOAD = 0x000c;
+ public static final int IC_KEYBOARD = 0x000d;
+ public static final int IC_GIST = 0x000e;
+ public static final int IC_GIST_PRIVATE = 0x000f;
+ public static final int IC_CODE_FILE = 0x0010;
+ public static final int IC_DOWNLOAD_UNKNOWN = 0x0010;
+ public static final int IC_TEXT_FILE = 0x0011;
+ public static final int IC_DOWNLOAD_TEXT = 0x0011;
+ public static final int IC_DOWNLOAD_MEDIA = 0x0012;
+ public static final int IC_DOWNLOAD_ZIP = 0x0013;
+ public static final int IC_DOWNLOAD_PDF = 0x0014;
+ public static final int IC_DOWNLOAD_TAG = 0x0015;
+ public static final int IC_DIRECTORY = 0x0016;
+ public static final int IC_SUBMODULE = 0x0017;
+ public static final int IC_PERSON = 0x0018;
+ public static final int IC_TEAM = 0x0019;
+ public static final int IC_MEMBER_ADDED = 0x001a;
+ public static final int IC_MEMBER_REMOVED = 0x001b;
+ public static final int IC_FOLLOW = 0x001c;
+ public static final int IC_WATCHING = 0x001d;
+ public static final int IC_UNWATCH = 0x001e;
+ public static final int IC_COMMIT = 0x001f;
+ public static final int IC_PUBLIC_FORK = 0x0020;
+ public static final int IC_FORK = 0x0020;
+ public static final int IC_PRIVATE_FORK = 0x0021;
+ public static final int IC_PULL_REQUEST = 0x0022;
+ public static final int IC_MERGE = 0x0023;
+ public static final int IC_PUBLIC_MIRROR = 0x0024;
+ public static final int IC_PRIVATE_MIRROR = 0x0025;
+ public static final int IC_ISSUE_OPENED = 0x0026;
+ public static final int IC_ISSUE_REOPENED = 0x0027;
+ public static final int IC_ISSUE_CLOSED = 0x0028;
+ public static final int IC_ISSUE_COMMENT = 0x0029;
+ public static final int IC_STAR = 0x002a;
+ public static final int IC_COMMIT_COMMENT = 0x002b;
+ public static final int IC_HELP = 0x002c;
+ public static final int IC_EXCLAMATION = 0x002d;
+ public static final int IC_SEARCH_INPUT = 0x002e;
+ public static final int IC_ADVANCED_SEARCH = 0x002f;
+ public static final int IC_NOTIFICATIONS = 0x0030;
+ public static final int IC_ACCOUNT_SETTINGS = 0x0031;
+ public static final int IC_LOGOUT = 0x0032;
+ public static final int IC_ADMIN_TOOLS = 0x0033;
+ public static final int IC_FEED = 0x0034;
+ public static final int IC_CLIPBOARD = 0x0035; /* UNOFFICIAL NAME */
+ public static final int IC_APPLE = 0x0036;
+ public static final int IC_WINDOWS = 0x0037;
+ public static final int IC_IOS = 0x0038;
+ public static final int IC_ANDROID = 0x0039;
+ public static final int IC_CONFIRM = 0x003a;
+ public static final int IC_UNREAD_NOTE = 0x003b;
+ public static final int IC_READ_NOTE = 0x003c;
+ public static final int IC_ARR_UP = 0x003d;
+ public static final int IC_ARR_RIGHT = 0x003e;
+ public static final int IC_ARR_DOWN = 0x003f;
+ public static final int IC_ARR_LEFT = 0x0040;
+ public static final int IC_PIN = 0x0041;
+ public static final int IC_GIFT = 0x0042;
+ public static final int IC_GRAPH = 0x0043;
+ public static final int IC_WRENCH = 0x0044;
+ public static final int IC_CREDIT_CARD = 0x0045;
+ public static final int IC_TIME = 0x0046;
+ public static final int IC_RUBY = 0x0047;
+ public static final int IC_PODCAST = 0x0048;
+ public static final int IC_KEY = 0x0049;
+ public static final int IC_FORCE_PUSH = 0x004a;
+ public static final int IC_SYNC = 0x004b;
+ public static final int IC_CLONE = 0x004c;
+ public static final int IC_DIFF = 0x004d;
+ public static final int IC_WATCHERS = 0x004e;
+ public static final int IC_DISCUSSION = 0x004f;
+ public static final int IC_DELETE_NOTE = 0x0050;
+ public static final int IC_REMOVE_CLOSE = 0x0050;
+ public static final int IC_REPLY = 0x0051;
+ public static final int IC_MAIL_STATUS = 0x0052;
+ public static final int IC_BLOCK = 0x0053;
+ public static final int IC_TAG_CREATE = 0x0054;
+ public static final int IC_TAG_DELETE = 0x0055;
+ public static final int IC_BRANCH_CREATE = 0x0056;
+ public static final int IC_BRANCH_DELETE = 0x0057;
+ public static final int IC_EDIT = 0x0058;
+ public static final int IC_INFO = 0x0059;
+ public static final int IC_ARR_COLLAPSED = 0x005a;
+ public static final int IC_ARR_EXPANDED = 0x005b;
+ public static final int IC_LINK = 0x005c;
+ public static final int IC_ADD = 0x005d;
+ public static final int IC_REORDER = 0x005e;
+ public static final int IC_CODE = 0x005f;
+ public static final int IC_LOCATION = 0x0060;
+ public static final int IC_U_LIST = 0x0061;
+ public static final int IC_O_LIST = 0x0062;
+ public static final int IC_QUOTEMARK = 0x0063;
+ public static final int IC_VERSION = 0x0064;
+ public static final int IC_BRIGHTNESS = 0x0065;
+ public static final int IC_FULLSCREEN = 0x0066;
+ public static final int IC_NORMALSCREEN = 0x0067;
+ public static final int IC_CALENDAR = 0x0068;
+ public static final int IC_BEER = 0x0069;
+ public static final int IC_LOCK = 0x006a;
+ public static final int IC_SECURE = 0x006a;
+ public static final int IC_ADDED = 0x006b;
+ public static final int IC_REMOVED = 0x006c;
+ public static final int IC_MODIFIED = 0x006d;
+ public static final int IC_MOVED = 0x006e;
+ public static final int IC_ADD_COMMENT = 0x006f;
+ public static final int IC_HORIZONTAL_RULE = 0x0070;
+ public static final int IC_ARR_RIGHT_MINI = 0x0071;
+ public static final int IC_JUMP_DOWN = 0x0072;
+ public static final int IC_JUMP_UP = 0x0073;
+
+ private
+ PaintDrawable mPaintDrawable;
+ private
+ TextView mTextView;
+
+ private
+ float mSize = 20.0f;
+ private
+ int mCurrentOcticon = 0x0000;
+
+ public
+ OcticonView(Context context)
+ {
+ super(context);
+ initialize(null);
+ }
+
+ public
+ OcticonView(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ initialize(attrs);
+ }
+
+ public
+ OcticonView(Context context, AttributeSet attrs, int defStyle)
+ {
+ super(context, attrs, defStyle);
+ initialize(attrs);
+ }
+
+ protected
+ void initialize(AttributeSet attrs)
+ {
+ if (OCTICON_TYPE == null)
+ OCTICON_TYPE = Typeface.createFromAsset(getContext().getAssets(), OCTICON_FONT);
+
+ mPaintDrawable = new PaintDrawable(Color.TRANSPARENT);
+ mPaintDrawable.setCornerRadius(OCTICON_CORNER_RADIUS);
+ setBackgroundDrawable(mPaintDrawable);
+
+ mTextView = new TextView(getContext());
+ mTextView.setBackgroundDrawable(null);
+ mTextView.setTypeface(OCTICON_TYPE);
+ mTextView.setTextColor(Color.WHITE);
+ LayoutParams textViewParams = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
+ textViewParams.addRule(CENTER_IN_PARENT);
+ addView(mTextView, textViewParams);
+
+ LayoutParams layoutParams = (LayoutParams) getLayoutParams();
+ if (layoutParams == null)
+ layoutParams = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
+ setLayoutParams(layoutParams);
+
+ if (attrs != null) {
+ int[] handledAttrs = {
+ android.R.attr.textSize,
+ android.R.attr.textColor
+ };
+ final TypedArray attrArray = getContext().obtainStyledAttributes(attrs, handledAttrs);
+ setGlyphSize(attrArray.getDimension(0, 24));
+ mTextView.setTextColor(attrArray.getColor(1, Color.WHITE));
+ }
+ setId(getId());
+ }
+
+ @Override
+ public
+ void setId(int id)
+ {
+ super.setId(id);
+
+ switch (id) {
+ default:
+ case NO_ID:
+ break;
+ case R.id.octicon_account_settings:
+ setOcticon(IC_ACCOUNT_SETTINGS);
+ break;
+ case R.id.octicon_add:
+ setOcticon(IC_ADD);
+ break;
+ case R.id.octicon_add_comment:
+ setOcticon(IC_ADD_COMMENT);
+ break;
+ case R.id.octicon_added:
+ setOcticon(IC_ADDED);
+ break;
+ case R.id.octicon_admin_tools:
+ setOcticon(IC_ADMIN_TOOLS);
+ break;
+ case R.id.octicon_advanced_search:
+ setOcticon(IC_ADVANCED_SEARCH);
+ break;
+ case R.id.octicon_android:
+ setOcticon(IC_ANDROID);
+ break;
+ case R.id.octicon_apple:
+ setOcticon(IC_APPLE);
+ break;
+ case R.id.octicon_arr_collapsed:
+ setOcticon(IC_ARR_COLLAPSED);
+ break;
+ case R.id.octicon_arr_down:
+ setOcticon(IC_ARR_DOWN);
+ break;
+ case R.id.octicon_arr_expanded:
+ setOcticon(IC_ARR_EXPANDED);
+ break;
+ case R.id.octicon_arr_left:
+ setOcticon(IC_ARR_LEFT);
+ break;
+ case R.id.octicon_arr_right:
+ setOcticon(IC_ARR_RIGHT);
+ break;
+ case R.id.octicon_arr_right_mini:
+ setOcticon(IC_ARR_RIGHT_MINI);
+ break;
+ case R.id.octicon_arr_up:
+ setOcticon(IC_ARR_UP);
+ break;
+ case R.id.octicon_beer:
+ setOcticon(IC_BEER);
+ break;
+ case R.id.octicon_blacktocat:
+ setOcticon(IC_BLACKTOCAT);
+ break;
+ case R.id.octicon_block:
+ setOcticon(IC_BLOCK);
+ break;
+ case R.id.octicon_branch_create:
+ setOcticon(IC_BRANCH_CREATE);
+ break;
+ case R.id.octicon_branch_delete:
+ setOcticon(IC_BRANCH_DELETE);
+ break;
+ case R.id.octicon_brightness:
+ setOcticon(IC_BRIGHTNESS);
+ break;
+ case R.id.octicon_calendar:
+ setOcticon(IC_CALENDAR);
+ break;
+ case R.id.octicon_clipboard:
+ setOcticon(IC_CLIPBOARD);
+ break;
+ case R.id.octicon_clone:
+ setOcticon(IC_CLONE);
+ break;
+ case R.id.octicon_code:
+ setOcticon(IC_CODE);
+ break;
+ case R.id.octicon_code_file:
+ setOcticon(IC_CODE_FILE);
+ break;
+ case R.id.octicon_commit:
+ setOcticon(IC_COMMIT);
+ break;
+ case R.id.octicon_commit_comment:
+ setOcticon(IC_COMMIT_COMMENT);
+ break;
+ case R.id.octicon_confirm:
+ setOcticon(IC_CONFIRM);
+ break;
+ case R.id.octicon_create:
+ setOcticon(IC_CREATE);
+ break;
+ case R.id.octicon_credit_card:
+ setOcticon(IC_CREDIT_CARD);
+ break;
+ case R.id.octicon_delete:
+ setOcticon(IC_DELETE);
+ break;
+ case R.id.octicon_delete_note:
+ setOcticon(IC_DELETE_NOTE);
+ break;
+ case R.id.octicon_diff:
+ setOcticon(IC_DIFF);
+ break;
+ case R.id.octicon_directory:
+ setOcticon(IC_DIRECTORY);
+ break;
+ case R.id.octicon_discussion:
+ setOcticon(IC_DISCUSSION);
+ break;
+ case R.id.octicon_download:
+ setOcticon(IC_DOWNLOAD);
+ break;
+ case R.id.octicon_download_media:
+ setOcticon(IC_DOWNLOAD_MEDIA);
+ break;
+ case R.id.octicon_download_pdf:
+ setOcticon(IC_DOWNLOAD_PDF);
+ break;
+ case R.id.octicon_download_tag:
+ setOcticon(IC_DOWNLOAD_TAG);
+ break;
+ case R.id.octicon_download_text:
+ setOcticon(IC_DOWNLOAD_TEXT);
+ break;
+ case R.id.octicon_download_unknown:
+ setOcticon(IC_DOWNLOAD_UNKNOWN);
+ break;
+ case R.id.octicon_download_zip:
+ setOcticon(IC_DOWNLOAD_ZIP);
+ break;
+ case R.id.octicon_edit:
+ setOcticon(IC_EDIT);
+ break;
+ case R.id.octicon_exclamation:
+ setOcticon(IC_EXCLAMATION);
+ break;
+ case R.id.octicon_feed:
+ setOcticon(IC_FEED);
+ break;
+ case R.id.octicon_follow:
+ setOcticon(IC_FOLLOW);
+ break;
+ case R.id.octicon_force_push:
+ setOcticon(IC_FORCE_PUSH);
+ break;
+ case R.id.octicon_fork:
+ setOcticon(IC_FORK);
+ break;
+ case R.id.octicon_fullscreen:
+ setOcticon(IC_FULLSCREEN);
+ break;
+ case R.id.octicon_gift:
+ setOcticon(IC_GIFT);
+ break;
+ case R.id.octicon_gist:
+ setOcticon(IC_GIST);
+ break;
+ case R.id.octicon_gist_private:
+ setOcticon(IC_GIST_PRIVATE);
+ break;
+ case R.id.octicon_graph:
+ setOcticon(IC_GRAPH);
+ break;
+ case R.id.octicon_help:
+ setOcticon(IC_HELP);
+ break;
+ case R.id.octicon_horizontal_rule:
+ setOcticon(IC_HORIZONTAL_RULE);
+ break;
+ case R.id.octicon_info:
+ setOcticon(IC_INFO);
+ break;
+ case R.id.octicon_invertocat:
+ setOcticon(IC_INVERTOCAT);
+ break;
+ case R.id.octicon_ios:
+ setOcticon(IC_IOS);
+ break;
+ case R.id.octicon_issue_closed:
+ setOcticon(IC_ISSUE_CLOSED);
+ break;
+ case R.id.octicon_issue_comment:
+ setOcticon(IC_ISSUE_COMMENT);
+ break;
+ case R.id.octicon_issue_opened:
+ setOcticon(IC_ISSUE_OPENED);
+ break;
+ case R.id.octicon_issue_reopened:
+ setOcticon(IC_ISSUE_REOPENED);
+ break;
+ case R.id.octicon_jump_down:
+ setOcticon(IC_JUMP_DOWN);
+ break;
+ case R.id.octicon_jump_up:
+ setOcticon(IC_JUMP_UP);
+ break;
+ case R.id.octicon_key:
+ setOcticon(IC_KEY);
+ break;
+ case R.id.octicon_keyboard:
+ setOcticon(IC_KEYBOARD);
+ break;
+ case R.id.octicon_link:
+ setOcticon(IC_LINK);
+ break;
+ case R.id.octicon_location:
+ setOcticon(IC_LOCATION);
+ break;
+ case R.id.octicon_lock:
+ setOcticon(IC_LOCK);
+ break;
+ case R.id.octicon_logout:
+ setOcticon(IC_LOGOUT);
+ break;
+ case R.id.octicon_mail_status:
+ setOcticon(IC_MAIL_STATUS);
+ break;
+ case R.id.octicon_member_added:
+ setOcticon(IC_MEMBER_ADDED);
+ break;
+ case R.id.octicon_member_removed:
+ setOcticon(IC_MEMBER_REMOVED);
+ break;
+ case R.id.octicon_merge:
+ setOcticon(IC_MERGE);
+ break;
+ case R.id.octicon_modified:
+ setOcticon(IC_MODIFIED);
+ break;
+ case R.id.octicon_moved:
+ setOcticon(IC_MOVED);
+ break;
+ case R.id.octicon_normalscreen:
+ setOcticon(IC_NORMALSCREEN);
+ break;
+ case R.id.octicon_notifications:
+ setOcticon(IC_NOTIFICATIONS);
+ break;
+ case R.id.octicon_o_list:
+ setOcticon(IC_O_LIST);
+ break;
+ case R.id.octicon_octocat:
+ setOcticon(IC_OCTOCAT);
+ break;
+ case R.id.octicon_person:
+ setOcticon(IC_PERSON);
+ break;
+ case R.id.octicon_pin:
+ setOcticon(IC_PIN);
+ break;
+ case R.id.octicon_podcast:
+ setOcticon(IC_PODCAST);
+ break;
+ case R.id.octicon_private_fork:
+ setOcticon(IC_PRIVATE_FORK);
+ break;
+ case R.id.octicon_private_mirror:
+ setOcticon(IC_PRIVATE_MIRROR);
+ break;
+ case R.id.octicon_private_repo:
+ setOcticon(IC_PRIVATE_REPO);
+ break;
+ case R.id.octicon_public_fork:
+ setOcticon(IC_PUBLIC_FORK);
+ break;
+ case R.id.octicon_public_mirror:
+ setOcticon(IC_PUBLIC_MIRROR);
+ break;
+ case R.id.octicon_public_repo:
+ setOcticon(IC_PUBLIC_REPO);
+ break;
+ case R.id.octicon_pull:
+ setOcticon(IC_PULL);
+ break;
+ case R.id.octicon_pull_request:
+ setOcticon(IC_PULL_REQUEST);
+ break;
+ case R.id.octicon_push:
+ setOcticon(IC_PUSH);
+ break;
+ case R.id.octicon_quotemark:
+ setOcticon(IC_QUOTEMARK);
+ break;
+ case R.id.octicon_read_note:
+ setOcticon(IC_READ_NOTE);
+ break;
+ case R.id.octicon_readme:
+ setOcticon(IC_README);
+ break;
+ case R.id.octicon_remove_close:
+ setOcticon(IC_REMOVE_CLOSE);
+ break;
+ case R.id.octicon_removed:
+ setOcticon(IC_REMOVED);
+ break;
+ case R.id.octicon_reorder:
+ setOcticon(IC_REORDER);
+ break;
+ case R.id.octicon_reply:
+ setOcticon(IC_REPLY);
+ break;
+ case R.id.octicon_repo_forked:
+ setOcticon(IC_REPO_FORKED);
+ break;
+ case R.id.octicon_ruby:
+ setOcticon(IC_RUBY);
+ break;
+ case R.id.octicon_search_input:
+ setOcticon(IC_SEARCH_INPUT);
+ break;
+ case R.id.octicon_secure:
+ setOcticon(IC_SECURE);
+ break;
+ case R.id.octicon_star:
+ setOcticon(IC_STAR);
+ break;
+ case R.id.octicon_submodule:
+ setOcticon(IC_SUBMODULE);
+ break;
+ case R.id.octicon_sync:
+ setOcticon(IC_SYNC);
+ break;
+ case R.id.octicon_tag_create:
+ setOcticon(IC_TAG_CREATE);
+ break;
+ case R.id.octicon_tag_delete:
+ setOcticon(IC_TAG_DELETE);
+ break;
+ case R.id.octicon_team:
+ setOcticon(IC_TEAM);
+ break;
+ case R.id.octicon_text_file:
+ setOcticon(IC_TEXT_FILE);
+ break;
+ case R.id.octicon_time:
+ setOcticon(IC_TIME);
+ break;
+ case R.id.octicon_u_list:
+ setOcticon(IC_U_LIST);
+ break;
+ case R.id.octicon_unread_note:
+ setOcticon(IC_UNREAD_NOTE);
+ break;
+ case R.id.octicon_unwatch:
+ setOcticon(IC_UNWATCH);
+ break;
+ case R.id.octicon_upload:
+ setOcticon(IC_UPLOAD);
+ break;
+ case R.id.octicon_version:
+ setOcticon(IC_VERSION);
+ break;
+ case R.id.octicon_watchers:
+ setOcticon(IC_WATCHERS);
+ break;
+ case R.id.octicon_watching:
+ setOcticon(IC_WATCHING);
+ break;
+ case R.id.octicon_wiki:
+ setOcticon(IC_WIKI);
+ break;
+ case R.id.octicon_windows:
+ setOcticon(IC_WINDOWS);
+ break;
+ case R.id.octicon_wrench:
+ setOcticon(IC_WRENCH);
+ break;
+ }
+ }
+
+ public
+ PaintDrawable getPaintDrawable()
+ {
+ return mPaintDrawable;
+ }
+
+ public
+ TextView getTextView()
+ {
+ return mTextView;
+ }
+
+ public
+ OcticonView setOcticon(final int icon)
+ {
+ mCurrentOcticon = icon;
+ if (mTextView.getPaint() != null) {
+ if (mTextView.getTextSize() > 16.0f)
+ mTextView.setText(
+ Html.fromHtml("&#x" + Integer.toHexString(MEGA + mCurrentOcticon) + ";"));
+ else
+ mTextView.setText(
+ Html.fromHtml("&#x" + Integer.toHexString(MINI + mCurrentOcticon) + ";"));
+ }
+ /*
+ * A hack to get rid of the bottom padding beneath these glyphs.
+ * setIncludeFontPadding(false) just causes a load of other problems, so this is really
+ * the only decent solution at the moment.
+ */
+ mTextView.setPadding(0, 0, 0, Math.round(mTextView.getPaint().ascent() / 10.0f));
+ return this;
+ }
+
+ public
+ OcticonView setShowTile(final boolean showBackground)
+ {
+ mPaintDrawable.setVisible(showBackground, false);
+ return this;
+ }
+
+ public
+ OcticonView setTileColor(final int color)
+ {
+ mPaintDrawable.getPaint().setColor(color);
+ return this;
+ }
+
+ public
+ OcticonView setGlyphSize(final float size)
+ {
+ mTextView.setTextSize(size);
+ return setOcticon(mCurrentOcticon);
+ }
+
+ public
+ OcticonView setGlyphColor(final int color)
+ {
+ mTextView.setTextColor(color);
+ return this;
+ }
+
+ public
+ Bitmap toBitmap(final int sizing)
+ {
+ if (!(getMeasuredHeight() > 0 && getMeasuredWidth() > 0)) {
+ measure(MeasureSpec.makeMeasureSpec(sizing, EXACTLY),
+ MeasureSpec.makeMeasureSpec(sizing, EXACTLY));
+ layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
+ }
+ final Bitmap bmp = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(),
+ Bitmap.Config.ARGB_8888);
+ final Canvas cvs = new Canvas(bmp);
+ draw(cvs);
+ return bmp;
+ }
+
+ public
+ Bitmap toBitmap()
+ {
+ return toBitmap(WRAP_CONTENT);
+ }
+
+ public
+ BitmapDrawable toDrawable(final int sizing)
+ {
+ return new BitmapDrawable(getResources(), toBitmap(sizing));
+ }
+
+ public
+ BitmapDrawable toDrawable()
+ {
+ return toDrawable(WRAP_CONTENT);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.