app推广:
一.基本情况
我们把推广和调研都放在了一起,主要是调研,主要通过调查问卷和直接访问的方式,让调查的人能够看到我们app的主要功能,
然后做出评价和对此改善的意见。调研推广主要通过QQ,微信和微博的群发功能和发表链接,让有兴趣的人参与进我们的调查。基本
情况如下图所示。
二.问卷和访问分析
通过调查问卷和直接访问我们得知调查的对象主要是广东省的在校大学生。超过一半的人觉得小学生可以用app的方式做数学题目。其余的
都是中立和反对的意见。总的来说四则运算app还是挺有市场前景的。对于出题的要超过半数的人认为要出不同难度的题目和生成不同类型和范
围的数给学生是算术题目的核心考虑问题。少部分觉得还需要加其他条件,比如阶乘等特殊条件运算。
在辅助功能方面。一半的人认为要加计算器的功能,其余建议更换皮肤等。对于我们app的初略评价,从五分为总分的情况看,调查出来的
平均分为4.14,看来调查人员对我们的app还是蛮有信心的。
以下是问卷截图。
1 2
3 4
三.总结
总的来说,如果要进入应用市场还是有一定的距离。因为还有需要算术方面的功能细节需要考虑。此外还有辅助功能,如果设计比较好看的
界面,把娱乐和做题结合吸引小学生是我们接下来要考虑的最主要的问题。推广的过程艰辛,不过用户还是挺期待的,愿接下来我们团队能够继
续完善成功发布在应用市场。
主要代码
按照老师发的极简github项目创建与提交链接做到第五步就卡住了,问题一些同学以及上网查了也不成功,所以只能上传代码了,等明天
看教程再放上github。
package com.example.operation; import mehdi.sakout.fancybuttons.FancyButton; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.ActionBar; import android.app.Activity; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; public class About extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.aboutlayout); } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. MenuInflater inflater=new MenuInflater(this); inflater.inflate(R.menu.main, menu); getMenuInflater().inflate(R.menu.main, menu); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case android.R.id.home: //创建启动MainActivity的Intent Intent intent=new Intent(this,MainActivity.class); //添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出 //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; case R.id.item1: startActivity(new Intent(About.this,Game.class)); break; case R.id.item2: startActivity(new Intent(About.this,Game1.class)); break; case R.id.item3: startActivity(new Intent(About.this,About.class)); break; case R.id.item4: startActivity(new Intent(About.this,About.class)); break; default: break; } return super.onOptionsItemSelected(item); } }
package com.example.operation; import java.util.Arrays; import mehdi.sakout.fancybuttons.FancyButton; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.ActionBar; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import bsh.EvalError; import bsh.Interpreter; import com.example.operation.R; @SuppressLint("NewApi") public class Game extends Activity { //EditText rsText = null; // private TextView tv2; private TextView textView1; private FancyButton btn_1; boolean isClear = false; private TextView tv=null; private TextView tv_tishu; private TextView tv_tishu1; private long start; private long end; private boolean flag = false; private EditText editText1; private EditText editText2; private String [] answer = new String [100]; private String [] right = new String [100]; private int jishu; long millisecond; long second; long minute; @TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gamelayout); // rsText = (EditText) findViewById(R.id.rsText);//editText1 是电脑答案 textView1 = (TextView) findViewById(R.id.textView3); tv = (TextView) findViewById(R.id.show); tv_tishu = (TextView) findViewById(R.id.tishutext); tv_tishu1 = (TextView) findViewById(R.id.textView2); editText1 = (EditText) findViewById(R.id.editText1);//editText1 是用户输入的题目 editText2 = (EditText) findViewById(R.id.editText2);//editText1 是用户输入的答案 // ActionBar actionBar = getActionBar();//获取ActionBar对象 // actionBar.setDisplayShowHomeEnabled(true);//显示应用程序图标 // actionBar.setDisplayHomeAsUpEnabled(true);//将应用程序图标转变为 Context context=getApplicationContext(); final Toast toast= Toast.makeText(context, "很遗憾,你的答案是错的", 1); answer [0]=""; btn_1 = (FancyButton) findViewById(R.id.is); btn_1.setOnClickListener(new OnClickListener() { int count = 0; // String[] readomHard = new String[20]; // readomHard[count] =String.valueOf(d); @Override public void onClick(View v) { count = count + 1; String a = null; String b = null; String c = null; //String d = null; //String e = null; String[] readomHard = new String[20]; jishu=Integer.parseInt(editText1.getText().toString()); //Toast.makeText(Game.this,jishu+"", 1).show(); //Toast.makeText(Game.this,count+"***", 1).show(); // readomHard[count] =String.valueOf(exp); if ( count<=Integer.parseInt(editText1.getText().toString()) || end < 6) { String[] readomWord = { "+", "-", "*", "/" }; int readomWordIndex = (int) (Math.random() * 4); c = readomWord[readomWordIndex]; a = String.valueOf((int) (Math.random() * 30)); b = String.valueOf((int) (Math.random() * 30)); //d = String.valueOf((int) (Math.random() * 30)); //e = readomWord[readomWordIndex2]; textView1.setText(a+c+b);// .... answer[count] = editText2.getText().toString(); // textView1.setText("("+a + c + b+")"+e+d);// .... String exp = textView1.getText().toString(); // rsText.setText(exp); //right[count-1]=exp; //获取答案跟比较答案/ /* String temp = editText2.getText().toString(); Double temp1 = Double.parseDouble (temp); temp1 = (int)(temp1*1000)/1000.0; */ /*Double exp1 = Double.parseDouble (temp); exp1 = (int)(exp1*1000)/1000.0; if(temp1==exp1){ Toast.makeText(Game.this, "Right ", Toast.LENGTH_LONG).show(); }*/ // if(Integer.parseInt(editText2.getText().toString())==Integer.parseInt(exp)) // { // Toast.makeText(Game.this,"right", 1).show(); // if (exp == null || exp.trim().length() == 0) // return; exp = getRs(exp); right[count-1]=exp; if (exp.endsWith(".0")) { exp = exp.substring(1, exp.indexOf(".0")); } // rsText.setText(exp); //Log.i("info",right[count-1]); isClear = false;// .... if (!flag && count==1){ flag=true; start(); } if(flag&&count>Integer.parseInt(editText1.getText().toString())) { pause(); } readomHard[count] = String.valueOf(exp); tv_tishu.setText("第" + count + "题"); // tv_tishu1.setText(readomHard[count]); } else { btn_1.setEnabled(false); answer[count] = editText2.getText().toString(); // Log.i("info",answer[count-1]); tv_tishu.setText("结束"); //跳转到新的页面里面去显示答案.顺便带走答案根用户答案的数组. //用户答案智能从1开始储存,电脑的从0 Log.i("info",answer[0]+"-"+answer[1]+"-"+answer[2]+"-"+answer[3]+"-"+answer[4]+"-"+answer[5]); Log.i("info",right[0]+"-"+right[1]+"-"+right[2]+"-"+right[3]+"-"+right[4]); Intent intent = new Intent(Game.this,Show.class); Bundle bundle = new Bundle(); bundle.putStringArray("user", answer); bundle.putStringArray("Computer", right); bundle.putInt("man", count-1); bundle.putString("time",toTime(end)); intent.putExtras(bundle); startActivity(intent); pause(); } }// .... }); } //////答案 /*** * @param exp * 算数表达式 * @return 根据表达式返回结果 */ private String getRs(String exp) { Interpreter bsh = new Interpreter(); Number result = null; try { exp = filterExp(exp); result = (Number) bsh.eval(exp); } catch (EvalError e) { e.printStackTrace(); isClear = true; return "算数公式错误"; } return result.intValue() + ""; } /** * @param exp * 算数表达式 * @return 因为计算过程中,全程需要有小数参与. */ private String filterExp(String exp) { String num[] = exp.split(""); String temp = null; int begin = 0, end = 0; for (int i = 1; i < num.length; i++) { temp = num[i]; if (temp.matches("[+-/()*]")) { if (temp.equals(".")) continue; end = i - 1; temp = exp.substring(begin, end); if (temp.trim().length() > 0 && temp.indexOf(".") < 0) num[i - 1] = num[i - 1] + ".0"; begin = end + 1; } } return Arrays.toString(num).replaceAll("[\[\], ]", ""); } //////////////////////////////////////////// private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); end = System.currentTimeMillis() - start; tv.setText(toTime(end)); } }; public class MyThread implements Runnable { @Override public void run() { while (flag) { try { Thread.sleep(100); Message message = handler.obtainMessage(); message.what = 1; handler.sendMessage(message); } catch (InterruptedException e) { e.printStackTrace(); } } } } public void pause() { flag = false; } public void start() { start = System.currentTimeMillis(); flag = true; new Thread(new MyThread()).start(); } private String toTime(long start) { millisecond = start % 1000; millisecond /= 100; start /= 1000; minute = start / 60; second = start % 60; minute %= 60; return String.format("%02d:%02d:%01d", minute, second, millisecond); } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. MenuInflater inflater=new MenuInflater(this); inflater.inflate(R.menu.main, menu); getMenuInflater().inflate(R.menu.main, menu); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case android.R.id.home: //创建启动MainActivity的Intent Intent intent=new Intent(this,MainActivity.class); //添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出 //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; case R.id.item1: startActivity(new Intent(Game.this,Game.class)); break; case R.id.item2: startActivity(new Intent(Game.this,Game1.class)); break; case R.id.item3: startActivity(new Intent(Game.this,About.class)); break; case R.id.item4: startActivity(new Intent(Game.this,About.class)); break; default: break; } return super.onOptionsItemSelected(item); } public boolean adjust(String answer,String useranswer){ /*double a = Double.parseDouble(answer); int temp = (int)Math.round(a*1000); a = temp/1000.0; double b =Double.parseDouble(useranswer); if(a!=b)*/ if(answer!=useranswer) return false; return true; } }
package com.example.operation; import java.util.Arrays; import mehdi.sakout.fancybuttons.FancyButton; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.ActionBar; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import bsh.EvalError; import bsh.Interpreter; import com.example.operation.R; @SuppressLint("NewApi") public class Game1 extends Activity { //EditText rsText = null; // private TextView tv2; private TextView textView1; private FancyButton btn_1; boolean isClear = false; private TextView tv=null; private TextView tv_tishu; private TextView tv_tishu1; private long start; private long end; private boolean flag = false; private EditText editText1; private EditText editText2; private String [] answer = new String [100]; private String [] right = new String [100]; private int jishu; long millisecond; long second; long minute; @TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gamelayout); // rsText = (EditText) findViewById(R.id.rsText);//editText1 是电脑答案 textView1 = (TextView) findViewById(R.id.textView3); tv = (TextView) findViewById(R.id.show); tv_tishu = (TextView) findViewById(R.id.tishutext); tv_tishu1 = (TextView) findViewById(R.id.textView2); editText1 = (EditText) findViewById(R.id.editText1);//editText1 是用户输入的题目 editText2 = (EditText) findViewById(R.id.editText2);//editText1 是用户输入的答案 // ActionBar actionBar = getActionBar();//获取ActionBar对象 // actionBar.setDisplayShowHomeEnabled(true);//显示应用程序图标 // actionBar.setDisplayHomeAsUpEnabled(true);//将应用程序图标转变为 Context context=getApplicationContext(); final Toast toast= Toast.makeText(context, "很遗憾,你的答案是错的", 1); answer [0]=""; btn_1 = (FancyButton) findViewById(R.id.is); btn_1.setOnClickListener(new OnClickListener() { int count = 0; // String[] readomHard = new String[20]; // readomHard[count] =String.valueOf(d); @Override public void onClick(View v) { count = count + 1; String a = null; String b = null; String c = null; String d = null; String e = null; String[] readomHard = new String[20]; jishu=Integer.parseInt(editText1.getText().toString()); //Toast.makeText(Game.this,jishu+"", 1).show(); //Toast.makeText(Game.this,count+"***", 1).show(); // readomHard[count] =String.valueOf(exp); if ( count<=Integer.parseInt(editText1.getText().toString()) || end < 6) { String[] readomWord = { "+", "-", "*", "/" }; int readomWordIndex = (int) (Math.random() * 4); int readomWordIndex2 = (int) (Math.random() * 4); c = readomWord[readomWordIndex]; a = String.valueOf((int) (Math.random() * 30)); b = String.valueOf((int) (Math.random() * 30)); d = String.valueOf((int) (Math.random() * 30)); e = readomWord[readomWordIndex2]; // textView1.setText(a+c+b);// .... answer[count] = editText2.getText().toString(); textView1.setText("("+a + c + b+")"+e+d);// .... String exp = textView1.getText().toString(); // rsText.setText(exp); //right[count-1]=exp; //获取答案跟比较答案/ /* String temp = editText2.getText().toString(); Double temp1 = Double.parseDouble (temp); temp1 = (int)(temp1*1000)/1000.0; */ /*Double exp1 = Double.parseDouble (temp); exp1 = (int)(exp1*1000)/1000.0; if(temp1==exp1){ Toast.makeText(Game.this, "Right ", Toast.LENGTH_LONG).show(); }*/ // if(Integer.parseInt(editText2.getText().toString())==Integer.parseInt(exp)) // { // Toast.makeText(Game.this,"right", 1).show(); // if (exp == null || exp.trim().length() == 0) // return; exp = getRs(exp); right[count-1]=exp; if (exp.endsWith(".0")) { exp = exp.substring(1, exp.indexOf(".0")); } // rsText.setText(exp); //Log.i("info",right[count-1]); isClear = false;// .... if (!flag && count==1){ flag=true; start(); } if(flag&&count>Integer.parseInt(editText1.getText().toString())) { pause(); } readomHard[count] = String.valueOf(exp); tv_tishu.setText("第" + count + "题"); // tv_tishu1.setText(readomHard[count]); } else { btn_1.setEnabled(false); answer[count] = editText2.getText().toString(); // Log.i("info",answer[count-1]); tv_tishu.setText("结束"); //跳转到新的页面里面去显示答案.顺便带走答案根用户答案的数组. //用户答案智能从1开始储存,电脑的从0 Log.i("info",answer[0]+"-"+answer[1]+"-"+answer[2]+"-"+answer[3]+"-"+answer[4]+"-"+answer[5]); Log.i("info",right[0]+"-"+right[1]+"-"+right[2]+"-"+right[3]+"-"+right[4]); Intent intent = new Intent(Game1.this,Show.class); Bundle bundle = new Bundle(); bundle.putStringArray("user", answer); bundle.putStringArray("Computer", right); bundle.putInt("man", count-1); bundle.putString("time",toTime(end)); intent.putExtras(bundle); startActivity(intent); pause(); } }// .... }); } //////答案 /*** * @param exp * 算数表达式 * @return 根据表达式返回结果 */ private String getRs(String exp) { Interpreter bsh = new Interpreter(); Number result = null; try { exp = filterExp(exp); result = (Number) bsh.eval(exp); } catch (EvalError e) { e.printStackTrace(); isClear = true; return "算数公式错误"; } return result.intValue() + ""; } /** * @param exp * 算数表达式 * @return 因为计算过程中,全程需要有小数参与. */ private String filterExp(String exp) { String num[] = exp.split(""); String temp = null; int begin = 0, end = 0; for (int i = 1; i < num.length; i++) { temp = num[i]; if (temp.matches("[+-/()*]")) { if (temp.equals(".")) continue; end = i - 1; temp = exp.substring(begin, end); if (temp.trim().length() > 0 && temp.indexOf(".") < 0) num[i - 1] = num[i - 1] + ".0"; begin = end + 1; } } return Arrays.toString(num).replaceAll("[\[\], ]", ""); } //////////////////////////////////////////// private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); end = System.currentTimeMillis() - start; tv.setText(toTime(end)); } }; public class MyThread implements Runnable { @Override public void run() { while (flag) { try { Thread.sleep(100); Message message = handler.obtainMessage(); message.what = 1; handler.sendMessage(message); } catch (InterruptedException e) { e.printStackTrace(); } } } } public void pause() { flag = false; } public void start() { start = System.currentTimeMillis(); flag = true; new Thread(new MyThread()).start(); } private String toTime(long start) { millisecond = start % 1000; millisecond /= 100; start /= 1000; minute = start / 60; second = start % 60; minute %= 60; return String.format("%02d:%02d:%01d", minute, second, millisecond); } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. MenuInflater inflater=new MenuInflater(this); inflater.inflate(R.menu.main, menu); getMenuInflater().inflate(R.menu.main, menu); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case android.R.id.home: //创建启动MainActivity的Intent Intent intent=new Intent(this,MainActivity.class); //添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出 //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; case R.id.item1: startActivity(new Intent(Game1.this,Game.class)); break; case R.id.item2: startActivity(new Intent(Game1.this,Game1.class)); break; case R.id.item3: startActivity(new Intent(Game1.this,About.class)); break; case R.id.item4: startActivity(new Intent(Game1.this,About.class)); break; default: break; } return super.onOptionsItemSelected(item); } public boolean adjust(String answer,String useranswer){ /*double a = Double.parseDouble(answer); int temp = (int)Math.round(a*1000); a = temp/1000.0; double b =Double.parseDouble(useranswer); if(a!=b)*/ if(answer!=useranswer) return false; return true; } }
package com.example.operation; import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.widget.RelativeLayout; public class Introduce extends Activity { int Draw[] = {R.drawable.aaa,R.drawable.bbb,R.drawable.ccc,R.drawable.ddd,R.drawable.eee,R.drawable.fff}; int currentPicIndex = 0; int changeIndex; RelativeLayout test; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.introduce); test = (RelativeLayout)findViewById(R.id.test); } @Override public boolean onTouchEvent(MotionEvent event) { test.setBackgroundResource(Draw[currentPicIndex]); changeIndex = currentPicIndex + 1; currentPicIndex = changeIndex; if(currentPicIndex > 5) currentPicIndex = 0; return super.onTouchEvent(event); }}
package com.example.operation; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; public class LoginActivity extends Activity { //账号输入框 EditText accountEdit; //密码输入框 EditText pwdEdit; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.login); //获取账号控件,并自动弹出软键盘 accountEdit = (EditText)findViewById(R.id.accountEdittext); accountEdit.setFocusable(true); accountEdit.setFocusableInTouchMode(true); accountEdit.requestFocus(); Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { InputMethodManager inputManager = (InputMethodManager) accountEdit .getContext().getSystemService( Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(accountEdit, 0); } }, 998); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case android.R.id.home: //创建启动MainActivity的Intent Intent intent=new Intent(this,MainActivity.class); //添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; } return super.onOptionsItemSelected(item);}}
package com.example.operation; import mehdi.sakout.fancybuttons.FancyButton; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.ActionBar; import android.app.Activity; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.TextView; import com.example.operation.R; //import com.example.tet.R; //import com.example.operation.MainActivity.MyThread; @SuppressLint("NewApi") public class MainActivity extends Activity { private FancyButton btn1; private FancyButton btn2; private FancyButton btn3; private FancyButton btn5; private FancyButton btn6; private TextView tv1; private boolean flag = false; // private long start; // private long end; // private boolean flag = false; @TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.menulayout); ActionBar actionBar = getActionBar();//获取ActionBar对象 actionBar.setDisplayShowHomeEnabled(true);//显示应用程序图标 actionBar.setDisplayHomeAsUpEnabled(true);//将应用程序图标转变为 // tv1=(TextView)findViewById(R.id.biaoti); btn1=(FancyButton)findViewById(R.id.button1); btn2=(FancyButton)findViewById(R.id.button2); btn3=(FancyButton)findViewById(R.id.button3); btn5=(FancyButton)findViewById(R.id.button5); btn6=(FancyButton)findViewById(R.id.button6); btn1.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent=new Intent(MainActivity.this,Game.class); startActivity(intent); } }); btn2.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent=new Intent(MainActivity.this,Game1.class); startActivity(intent); } }); btn3.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent=new Intent(MainActivity.this,Introduce.class); startActivity(intent); } }); btn5.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent=new Intent(MainActivity.this,About.class); startActivity(intent); } }); btn6.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent=new Intent(MainActivity.this,LoginActivity.class); startActivity(intent); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case android.R.id.home: //创建启动MainActivity的Intent Intent intent=new Intent(this,MainActivity.class); //添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; case R.id.item1: startActivity(new Intent(MainActivity.this,Game.class)); break; case R.id.item2: startActivity(new Intent(MainActivity.this,Game1.class)); break; case R.id.item3: startActivity(new Intent(MainActivity.this,About.class)); break; case R.id.item4: startActivity(new Intent(MainActivity.this,About.class)); break; default: break; } return super.onOptionsItemSelected(item); }}
package com.example.operation; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.ActionBar; import android.app.Activity; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.TextView; public class Show extends Activity { private TextView t1; private TextView t2; private TextView t3; private TextView t4; private TextView t5; private TextView t6; private TextView t7; private TextView t8; private TextView t9; private TextView t10; private TextView t11; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub int count=0; super.onCreate(savedInstanceState); setContentView(R.layout.showlayout); TextView t[]=new TextView[100]; t1 = (TextView)findViewById(R.id.textView1); t2 = (TextView)findViewById(R.id.textView2); t3 = (TextView)findViewById(R.id.textView3); t4 = (TextView)findViewById(R.id.textView4); t5 = (TextView)findViewById(R.id.textView5); t6 = (TextView)findViewById(R.id.textView6); t7 = (TextView)findViewById(R.id.textView7); t8 = (TextView)findViewById(R.id.textView8); t9 = (TextView)findViewById(R.id.textView9); t10 = (TextView)findViewById(R.id.textView10); t11= (TextView)findViewById(R.id.time); //获取 Bundle bundle2 = getIntent().getExtras(); String []user = new String[100]; String []computer = new String[100]; String time ; int man; user = bundle2.getStringArray("user"); computer = bundle2.getStringArray("Computer"); man=bundle2.getInt("man"); time=bundle2.getString("time"); t11.setText("答题所用的时间为:"+time); // Log.i("info",computer[0]+"*"+computer[1]+"*"+computer[2]+"*"+computer[3]+"*"+computer[4] // +"*"+computer[5]+"*"+computer[6]+"*"+computer[7]+"*"+computer[8]+"*"+computer[9] ); //Log.i("info",user[2]+"*"+user[3]+"*"+user[4]+"*"+user[5]+"*"+user[6]+"*"+user[7]+"*"+user[8] // +"*"+user[9]+"*"+user[10]+"*"+user[11]); // Log.i("info",""+man); if (user[2].equals(computer[0])) t1.setText("你答对了第一题"+","+"答案是"+":"+computer[0]); else t1.setText("你答错了第一题"+","+"答案是"+":"+computer[0]); if (user[3]==null&&computer[1]==null) t2.setText("2"); else if (user[3].equals(computer[1])) t2.setText("你答对了第二题"+","+"答案是"+":"+computer[1]); else t2.setText("你答错了第二题"+","+"答案是"+":"+computer[1]); if (user[4]==null&&computer[2]==null) t3.setText("3"); else if (user[4].equals(computer[2])) t3.setText("你答对了第三题"+","+"答案是"+":"+computer[2]); else t3.setText("你答错了第三题"+","+"答案是"+":"+computer[2]); if (user[5]==null&&computer[3]==null) t4.setText("4"); else if (user[5].equals(computer[3])) t4.setText("你答对了第四题"+","+"答案是"+":"+computer[3]); else t4.setText("你答错了第四题"+","+"答案是"+":"+computer[3]); if (user[6]==null&&computer[4]==null) t5.setText("5"); else if (user[6].equals(computer[4])) t5.setText("你答对了第五题"+","+"答案是"+":"+computer[4]); else t5.setText("你答错了第五题"+","+"答案是"+":"+computer[4]); if (user[7]==null&&computer[5]==null) t6.setText("6"); else if (user[7].equals(computer[5])) t6.setText("你答对了第六题"+","+"答案是"+":"+computer[5]); else t6.setText("你答错了第六题"+","+"答案是"+":"+computer[5]); if (user[8]==null&&computer[6]==null) t7.setText("7"); else if (user[8].equals(computer[6])) t7.setText("你答对了第七题"+","+"答案是"+":"+computer[6]); else t7.setText("你答错了第七题"+","+"答案是"+":"+computer[6]); if (user[9]==null&&computer[7]==null) t8.setText("8"); else if (user[9].equals(computer[7])) t8.setText("你答对了第八题"+","+"答案是"+":"+computer[7]); else t8.setText("你答错了第八题"+","+"答案是"+":"+computer[7]); if (user[10]==null&&computer[8]==null) t9.setText("9"); else if (user[10].equals(computer[8])) t9.setText("你答对了第九题"+","+"答案是"+":"+computer[8]); else t9.setText("你答错了第九题"+","+"答案是"+":"+computer[8]); if (user[11]==null&&computer[9]==null) t10.setText("10"); else if (user[11].equals(computer[9])) t10.setText("你答对了第十题"+","+"答案是"+":"+computer[9]); else t10.setText("你答错了第十题"+","+"答案是"+":"+computer[9]); } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. MenuInflater inflater=new MenuInflater(this); inflater.inflate(R.menu.main, menu); getMenuInflater().inflate(R.menu.main, menu); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case android.R.id.home: //创建启动MainActivity的Intent Intent intent=new Intent(this,MainActivity.class); //添加额外的Flag,将Activity栈中处于MainActivity之上的Activity弹出 //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; case R.id.item1: startActivity(new Intent(Show.this,Game.class)); break; case R.id.item2: startActivity(new Intent(Show.this,Game1.class)); break; case R.id.item3: startActivity(new Intent(Show.this,About.class)); break; case R.id.item4: startActivity(new Intent(Show.this,About.class)); break; default: break; } return super.onOptionsItemSelected(item); } }
package com.example.operation; import android.annotation.SuppressLint; import android.os.Handler; import android.os.Message; import android.widget.Button; import android.widget.TextView; public class time { private TextView tv; private long start; private long end; private boolean flag = false; private Button btnStart; @SuppressLint("HandlerLeak") private Handler handler = new Handler() { @Override public void handleMessage(android.os.Message msg) { super.handleMessage(msg); end = System.currentTimeMillis() - start; tv.setText(toTime(end)); } }; public class MyThread implements Runnable { @Override public void run() { while (flag) { try { Thread.sleep(100); Message message = handler.obtainMessage(); message.what = 1; handler.sendMessage(message); } catch (InterruptedException e) { e.printStackTrace(); } } } } public void pause() { flag = false; } public void start() { start = System.currentTimeMillis(); flag = true; new Thread(new MyThread()).start(); } private String toTime(long start) { long millisecond = start % 1000; millisecond /= 100; start /= 1000; long minute = start / 60; long second = start % 60; minute %= 60; return String.format("%02d:%02d:%01d", minute, second, millisecond); } }
package mehdi.sakout.fancybuttons; import java.util.ArrayList; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.StateListDrawable; import android.util.AttributeSet; import android.util.Log; import android.view.Gravity; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.example.operation.*; @SuppressWarnings("unused") public class FancyButton extends LinearLayout{ private Context mContext; // # Background Attributes private int mDefaultBackgroundColor = Color.BLACK; private int mFocusBackgroundColor = 0; // # Text Attributes private int mDefaultTextColor = Color.WHITE; private int mDefaultIconColor = Color.WHITE; private int mTextPosition = 1; private int mDefaultTextSize = 15; private int mDefaultTextGravity = 0x11; // Gravity.CENTER private String mText = null; // # Icon Attributes private Drawable mIconResource = null; private int mFontIconSize = 15; private String mFontIcon = null; private int mIconPosition = 1; private int mIconPaddingLeft = 10; private int mIconPaddingRight = 10; private int mIconPaddingTop = 0; private int mIconPaddingBottom = 0; private int mBorderColor = Color.TRANSPARENT; private int mBorderWidth = 0; private int mRadius = 0; private Typeface mTextTypeFace = null; private Typeface mIconTypeFace = null; /** * Tags to identify icon position */ public static final int POSITION_LEFT = 1; public static final int POSITION_RIGHT = 2; public static final int POSITION_TOP = 3; public static final int POSITION_BOTTOM = 4; private String mDefaultIconFont = "fontawesome.ttf"; private String mDefaultTextFont = "robotoregular.ttf"; private ImageView mIconView; private TextView mFontIconView; private TextView mTextView; private boolean mGhost = false ; // Default is a solid button ! /** * Default constructor * @param context : Context */ public FancyButton(Context context){ super(context); this.mContext = context; mTextTypeFace = Typeface.createFromAsset(mContext.getAssets(), String.format("fonts/%s",mDefaultTextFont)); mIconTypeFace = Typeface.createFromAsset(mContext.getAssets(), String.format("iconfonts/%s",mDefaultIconFont)); initializeFancyButton(); } /** * Default constructor called from Layouts * @param context : Context * @param attrs : Attributes Array */ public FancyButton(Context context, AttributeSet attrs){ super(context,attrs); this.mContext = context; TypedArray attrsArray = context.obtainStyledAttributes(attrs,R.styleable.FancyButtonsAttrs, 0, 0); initAttributsArray(attrsArray); attrsArray.recycle(); initializeFancyButton(); } /** * Initialize Button dependencies * - Initialize Button Container : The LinearLayout * - Initialize Button TextView * - Initialize Button Icon * - Initialize Button Font Icon */ private void initializeFancyButton(){ initializeButtonContainer(); mTextView = setupTextView(); mIconView = setupIconView(); mFontIconView = setupFontIconView(); int iconIndex,textIndex; View view1,view2; if(mIconView == null && mFontIconView == null && mTextView == null){ Button tempTextView = new Button(mContext); tempTextView.setText("Fancy Button"); this.addView(tempTextView); }else{ this.removeAllViews(); setupBackground(); ArrayList<View> views = new ArrayList<View>(); if(mIconPosition == POSITION_LEFT || mIconPosition == POSITION_TOP){ if(mIconView != null){ views.add(mIconView); } if(mFontIconView != null){ views.add(mFontIconView); } if(mTextView != null){ views.add(mTextView); } }else{ if(mTextView != null){ views.add(mTextView); } if(mIconView != null){ views.add(mIconView); } if(mFontIconView != null){ views.add(mFontIconView); } } for(View view : views){ this.addView(view); } } } /** * Setup Text View * @return : TextView */ private TextView setupTextView(){ if (mText != null) { TextView textView = new TextView(mContext); textView.setText(mText); textView.setGravity(mDefaultTextGravity); textView.setTextColor(mDefaultTextColor); textView.setTextSize(mDefaultTextSize); textView.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); if (!isInEditMode() && mTextTypeFace!=null) { textView.setTypeface(mTextTypeFace); } return textView; } return null; } /** * Setup Font Icon View * @return : TextView */ private TextView setupFontIconView(){ if(mFontIcon!=null){ TextView fontIconView = new TextView(mContext); fontIconView.setTextColor(mDefaultIconColor); LayoutParams iconTextViewParams = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,android.view.ViewGroup.LayoutParams.WRAP_CONTENT); iconTextViewParams.rightMargin = mIconPaddingRight; iconTextViewParams.leftMargin = mIconPaddingLeft; iconTextViewParams.topMargin = mIconPaddingTop; iconTextViewParams.bottomMargin = mIconPaddingBottom; if(mTextView != null){ if(mIconPosition==POSITION_TOP || mIconPosition==POSITION_BOTTOM){ iconTextViewParams.gravity = Gravity.CENTER; fontIconView.setGravity(Gravity.CENTER); } else{ fontIconView.setGravity(Gravity.CENTER_VERTICAL); iconTextViewParams.gravity = Gravity.CENTER_VERTICAL; } }else{ iconTextViewParams.gravity = Gravity.CENTER; fontIconView.setGravity(Gravity.CENTER_VERTICAL); } fontIconView.setLayoutParams(iconTextViewParams); if(!isInEditMode()){ fontIconView.setTextSize(mFontIconSize); fontIconView.setText(mFontIcon); fontIconView.setTypeface(mIconTypeFace); }else{ fontIconView.setText("O"); } return fontIconView; } return null; } /** * Text Icon resource view * @return : ImageView */ private ImageView setupIconView(){ if (mIconResource != null){ ImageView iconView = new ImageView(mContext); iconView.setImageDrawable(mIconResource); iconView.setPadding(mIconPaddingLeft, mIconPaddingTop, mIconPaddingRight, mIconPaddingBottom); LayoutParams iconViewParams = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,android.view.ViewGroup.LayoutParams.WRAP_CONTENT); if(mTextView!=null){ if(mIconPosition==POSITION_TOP || mIconPosition==POSITION_BOTTOM) iconViewParams.gravity = Gravity.CENTER; else iconViewParams.gravity = Gravity.START; iconViewParams.rightMargin = 10; iconViewParams.leftMargin = 10; }else{ iconViewParams.gravity = Gravity.CENTER_VERTICAL; } iconView.setLayoutParams(iconViewParams); return iconView; } return null; } /** * Initialize Attributes arrays * @param attrsArray : Attributes array */ private void initAttributsArray(TypedArray attrsArray){ mDefaultBackgroundColor = attrsArray.getColor(R.styleable.FancyButtonsAttrs_fb_defaultColor,mDefaultBackgroundColor); mFocusBackgroundColor = attrsArray.getColor(R.styleable.FancyButtonsAttrs_fb_focusColor,mFocusBackgroundColor); mDefaultTextColor = attrsArray.getColor(R.styleable.FancyButtonsAttrs_fb_textColor,mDefaultTextColor); // if default color is set then the icon's color is the same (the default for icon's color) mDefaultIconColor = attrsArray.getColor(R.styleable.FancyButtonsAttrs_fb_iconColor,mDefaultTextColor); mDefaultTextSize = (int) attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_textSize,mDefaultTextSize); mDefaultTextGravity = attrsArray.getInt(R.styleable.FancyButtonsAttrs_fb_textGravity, mDefaultTextGravity); mBorderColor = attrsArray.getColor(R.styleable.FancyButtonsAttrs_fb_borderColor,mBorderColor); mBorderWidth = (int) attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_borderWidth,mBorderWidth); mRadius = (int)attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_radius,mRadius); mFontIconSize = (int)attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_fontIconSize,mFontIconSize); mIconPaddingLeft = (int)attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_iconPaddingLeft,mIconPaddingLeft); mIconPaddingRight = (int)attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_iconPaddingRight,mIconPaddingRight); mIconPaddingTop = (int)attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_iconPaddingTop,mIconPaddingTop); mIconPaddingBottom = (int)attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_iconPaddingBottom,mIconPaddingBottom); mGhost = attrsArray.getBoolean(R.styleable.FancyButtonsAttrs_fb_ghost, mGhost); String text = attrsArray.getString(R.styleable.FancyButtonsAttrs_fb_text); mIconPosition = attrsArray.getInt(R.styleable.FancyButtonsAttrs_fb_iconPosition,mIconPosition); String fontIcon = attrsArray.getString(R.styleable.FancyButtonsAttrs_fb_fontIconResource); String iconFontFamily = attrsArray.getString(R.styleable.FancyButtonsAttrs_fb_iconFont); String textFontFamily = attrsArray.getString(R.styleable.FancyButtonsAttrs_fb_textFont); Drawable icon = null; try{ mIconResource = attrsArray.getDrawable(R.styleable.FancyButtonsAttrs_fb_iconResource); }catch(Exception e){ mIconResource = null; } if(fontIcon!=null) mFontIcon = fontIcon; if(text!=null) mText = text; if(!isInEditMode()){ if(iconFontFamily!=null){ try{ mIconTypeFace = Typeface.createFromAsset(mContext.getAssets(), String.format("iconfonts/%s",iconFontFamily)); }catch(Exception e){ Log.e("Fancy",e.getMessage()); mIconTypeFace= Typeface.createFromAsset(mContext.getAssets(), String.format("iconfonts/%s",mDefaultIconFont)); } }else{ mIconTypeFace= Typeface.createFromAsset(mContext.getAssets(), String.format("iconfonts/%s",mDefaultIconFont)); } if(textFontFamily!=null){ try{ mTextTypeFace = Typeface.createFromAsset(mContext.getAssets(), String.format("fonts/%s",textFontFamily)); } catch(Exception e){ mTextTypeFace= Typeface.createFromAsset(mContext.getAssets(), String.format("fonts/%s",mDefaultTextFont)); } }else{ mTextTypeFace= Typeface.createFromAsset(mContext.getAssets(), String.format("fonts/%s",mDefaultTextFont)); } } } @SuppressLint("NewApi") private void setupBackground(){ // Default Drawable GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadius(mRadius); if (mGhost){ drawable.setColor(getResources().getColor(android.R.color.transparent)); // Hollow Background } else { drawable.setColor(mDefaultBackgroundColor); } if (mBorderColor != 0) { drawable.setStroke(mBorderWidth, mBorderColor); } // Focus/Pressed Drawable GradientDrawable drawable2 = new GradientDrawable(); drawable2.setCornerRadius(mRadius); if (mGhost){ drawable2.setColor(getResources().getColor(android.R.color.transparent)); // No focus color } else { drawable2.setColor(mFocusBackgroundColor); } if (mBorderColor != 0) { if (mGhost) { drawable2.setStroke(mBorderWidth, mFocusBackgroundColor); // Border is the main part of button now } else { drawable2.setStroke(mBorderWidth, mBorderColor); } } StateListDrawable states = new StateListDrawable(); if(mFocusBackgroundColor!=0){ states.addState(new int[] { android.R.attr.state_pressed }, drawable2); states.addState(new int[] { android.R.attr.state_focused }, drawable2); } states.addState(new int[] {}, drawable); if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { this.setBackgroundDrawable(states); } else { this.setBackground(states); } } /** * Initialize button container */ private void initializeButtonContainer(){ if(mIconPosition == POSITION_TOP || mIconPosition == POSITION_BOTTOM){ this.setOrientation(LinearLayout.VERTICAL); }else{ this.setOrientation(LinearLayout.HORIZONTAL); } LayoutParams containerParams = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,android.view.ViewGroup.LayoutParams.WRAP_CONTENT); this.setLayoutParams(containerParams); this.setGravity(Gravity.CENTER); this.setClickable(true); this.setFocusable(true); if(mIconResource==null && mFontIcon==null && getPaddingLeft()==0 && getPaddingRight()==0 && getPaddingTop()==0 && getPaddingBottom()==0){ this.setPadding(20, 20, 20, 20); } } /** * Set Text of the button * @param text : Text */ public void setText(String text){ this.mText = text; if(mTextView == null) initializeFancyButton(); else mTextView.setText(text); } /** * Set the color of text * @param color : Color * use Color.parse('#code') */ public void setTextColor(int color){ this.mDefaultTextColor = color; if(mTextView == null) initializeFancyButton(); else mTextView.setTextColor(color); } /** * Setting the icon's color independent of the text color * @param color : Color */ public void setIconColor(int color){ if(mFontIconView != null) { mFontIconView.setTextColor(color); } } /** * Set Background color of the button * @param color : use Color.parse('#code') */ @Override public void setBackgroundColor(int color){ this.mDefaultBackgroundColor = color; if(mIconView != null || mFontIconView != null || mTextView != null){ this.setupBackground(); } } /** * Set Focus color of the button * @param color : use Color.parse('#code') */ public void setFocusBackgroundColor(int color){ this.mFocusBackgroundColor = color; if(mIconView != null || mFontIconView != null || mTextView != null) this.setupBackground(); } /** * Set the size of Text * @param textSize : Text Size */ public void setTextSize(int textSize){ this.mDefaultTextSize = textSize; if(mTextView != null) mTextView.setTextSize(textSize); } /** * Set the gravity of Text * @param gravity : Text Gravity */ public void setTextGravity(int gravity) { this.mDefaultTextGravity = gravity; if (mTextView != null) { mTextView.setGravity(gravity); } } /** * Set Padding for mIconView and mFontIconSize * @param paddingLeft : Padding Left * @param paddingTop : Padding Top * @param paddingRight : Padding Right * @param paddingBottom : Padding Bottom */ public void setIconPadding(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom){ this.mIconPaddingLeft = paddingLeft; this.mIconPaddingTop = paddingTop; this.mIconPaddingRight = paddingRight; this.mIconPaddingBottom = paddingBottom; if(mIconView != null){ mIconView.setPadding(this.mIconPaddingLeft, this.mIconPaddingTop, this.mIconPaddingRight, this.mIconPaddingBottom); } if(mFontIconView != null){ mFontIconView.setPadding(this.mIconPaddingLeft, this.mIconPaddingTop, this.mIconPaddingRight, this.mIconPaddingBottom); } } /** * Set an icon from resources to the button * @param drawable : Drawable resource */ public void setIconResource(int drawable){ this.mIconResource = mContext.getResources().getDrawable(drawable); if(mIconView == null || mFontIconView != null) { mFontIconView= null; initializeFancyButton(); } else mIconView.setImageDrawable(mIconResource); } /** * Set a font icon to the button (eg FFontAwesome or Entypo...) * @param icon : Icon value eg : uf082 */ public void setIconResource(String icon){ this.mFontIcon = icon; if(mFontIconView == null) { mIconView=null; initializeFancyButton(); } else mFontIconView.setText(icon); } /** * Set Icon size of the button (for only font icons) * @param iconSize : Icon Size */ public void setFontIconSize(int iconSize){ this.mFontIconSize = iconSize; if(mFontIconView!=null) mFontIconView.setTextSize(iconSize); } /** * Set Icon Position * Use the global variables (FancyButton.POSITION_LEFT, FancyButton.POSITION_RIGHT, FancyButton.POSITION_TOP, FancyButton.POSITION_BOTTOM) * @param position : Position */ public void setIconPosition(int position){ if(position>0 && position<5) mIconPosition = position; else mIconPosition = POSITION_LEFT; initializeFancyButton(); } /** * Set color of the button border * @param color : Color * use Color.parse('#code') */ public void setBorderColor(int color){ this.mBorderColor = color; if(mIconView!=null || mFontIconView!=null || mTextView!=null){ this.setupBackground(); } } /** * Set Width of the button * @param width : Width */ public void setBorderWidth(int width){ this.mBorderWidth = width; if(mIconView != null || mFontIconView != null || mTextView != null){ this.setupBackground(); } } /** * Set Border Radius of the button * @param radius : Radius */ public void setRadius(int radius){ this.mRadius = radius; if(mIconView != null || mFontIconView != null || mTextView != null){ this.setupBackground(); } } /** * Set custom font for button Text * @param fontName : Font Name * Place your text fonts in assets/fonts/ */ public void setCustomTextFont(String fontName){ try{ mTextTypeFace = Typeface.createFromAsset(mContext.getAssets(), String.format("fonts/%s",fontName)); }catch(Exception e){ Log.e("FancyButtons",e.getMessage()); mTextTypeFace= Typeface.createFromAsset(mContext.getAssets(), String.format("fonts/%s",mDefaultTextFont)); } if(mTextView==null) initializeFancyButton(); else mTextView.setTypeface(mTextTypeFace); } /** * Set Custom font for button icon * @param fontName : Font Name * Place your icon fonts in assets/iconfonts/ */ public void setCustomIconFont(String fontName){ try{ mIconTypeFace = Typeface.createFromAsset(mContext.getAssets(), String.format("iconfonts/%s",fontName)); }catch(Exception e){ Log.e("FancyButtons",e.getMessage()); mIconTypeFace= Typeface.createFromAsset(mContext.getAssets(), String.format("iconfonts/%s",mDefaultIconFont)); } if(mFontIconView == null) initializeFancyButton(); else mFontIconView.setTypeface(mIconTypeFace); } /** * Setting the button to have hollow or solid shape * @param ghost */ public void setGhost(boolean ghost) { this.mGhost = ghost; if(mIconView != null || mFontIconView != null || mTextView != null){ this.setupBackground(); } } /** * Return Text of the button * @return Text */ public CharSequence getText(){ if (mTextView != null) return mTextView.getText(); else return ""; } /** * Return TextView Object of the FancyButton * @return TextView Object */ public TextView getTextViewObject(){ return mTextView; } /** * Return Icon Font of the FancyButton * @return TextView Object */ public TextView getIconFontObject(){ return mFontIconView; } /** * Return Icon of the FancyButton * @return ImageView Object */ public ImageView getIconImageObject(){ return mIconView; } }