導航:首頁 > 操作系統 > android統計庫

android統計庫

發布時間:2024-08-21 16:51:55

⑴ 在android中要實現圖表統計該怎麼做

package com.yzxy.draw;

import java.util.ArrayList;
import java.util.HashMap;
import com.yzxy.draw.tools.Tools;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.graphics.Typeface;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

@SuppressLint("ViewConstructor")
class MyTuView extends View{

public static final int RECT_SIZE = 10;
private Point mSelectedPoint = null;
public static enum Mstyle
{
Line,scroll
}

private Mstyle mstyle=Mstyle.Line;
private Point[] mPoints = new Point[8];

Context context;
Activity act;
int bheight=0;
Tools tool=new Tools();
HashMap map;
ArrayList dlk;
int totalvalue=30;
int pjvalue=5;
String xstr,ystr;
int margint=15;
int marginb=40;
int c=0;
int resid=0;
Boolean isylineshow;

public MyTuView(Context context,HashMap map,int totalvalue,int pjvalue,String xstr,String ystr,Boolean isylineshow)
{
super(context);
this.context=context;
this.act = (Activity)context;
this.map=map;
this.totalvalue=totalvalue;
this.pjvalue=pjvalue;
this.xstr=xstr;
this.ystr=ystr;
this.isylineshow=isylineshow;
act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}

@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// canvas.drawColor(Color.GRAY);
if(c!=0)
this.setbg(c);
if(resid!=0)
this.setBackgroundResource(resid);
dlk=tool.getintfrommap(map);
int height=getHeight();
if(bheight==0)
bheight=height-marginb;

int width=getWidth();

Log.i("w", getWidth()+":"+getHeight());
int blwidh=tool.dip2px(context,50);
int pjsize=totalvalue/pjvalue;

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.GRAY);
paint.setStrokeWidth(1);
paint.setStyle(Style.STROKE);

// 畫直線(橫向)
for(int i=0;i xlist=new ArrayList();//記錄每個x的值
//畫直線(縱向)
for(int i=0;i dlk,HashMap map,ArrayList xlist,int max,int h)
{
Point[] points=new Point[dlk.size()];
for(int i=0;i getMap() {
return map;
}

public void setMap(HashMap map) {
this.map = map;
}

public int getTotalvalue() {
return totalvalue;
}

public void setTotalvalue(int totalvalue) {
this.totalvalue = totalvalue;
}

public int getPjvalue() {
return pjvalue;
}

public void setPjvalue(int pjvalue) {
this.pjvalue = pjvalue;
}

public String getXstr() {
return xstr;
}

public void setXstr(String xstr) {
this.xstr = xstr;
}

public String getYstr() {
return ystr;
}

public void setYstr(String ystr) {
this.ystr = ystr;
}

public int getMargint() {
return margint;
}

public void setMargint(int margint) {
this.margint = margint;
}

public Boolean getIsylineshow() {
return isylineshow;
}

public void setIsylineshow(Boolean isylineshow) {
this.isylineshow = isylineshow;
}

public int getMarginb() {
return marginb;
}

public void setMarginb(int marginb) {
this.marginb = marginb;
}

public Mstyle getMstyle() {
return mstyle;
}

public void setMstyle(Mstyle mstyle) {
this.mstyle = mstyle;
}

public int getBheight() {
return bheight;
}

public void setBheight(int bheight) {
this.bheight = bheight;
}

public int getC() {
return c;
}

public void setC(int c) {
this.c = c;
}

public int getResid() {
return resid;
}

public void setResid(int resid) {
this.resid = resid;
}

}

代碼片段
package com.yzxy.draw.tools;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Environment;

public class Tools
{
private final static String ALBUM_PATH = Environment.getExternalStorageDirectory() + "/yueqiu/";

public int dip2px(Context context, float dpValue)
{
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}

public int px2dip(Context context, float pxValue)
{
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}

public ArrayList getintfrommap(HashMap map)
{
ArrayList dlk=new ArrayList();
int position=0;
@SuppressWarnings("rawtypes")
Set set= map.entrySet();
@SuppressWarnings("rawtypes")
Iterator iterator = set.iterator();

while(iterator.hasNext())
{
@SuppressWarnings("rawtypes")
Map.Entry mapentry = (Map.Entry)iterator.next();
dlk.add((Double)mapentry.getKey());
}
for(int i=0;i

代碼片段
package com.yzxy.draw;

import java.io.IOException;
import java.util.HashMap;

import com.yzxy.draw.MyTuView.Mstyle;
import com.yzxy.draw.tools.Tools;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;

import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.Toast;
import android.app.Activity;
import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
import android.graphics.Color;

public class MainActivity extends Activity {

MyTuView tu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

HashMap map=new HashMap();
map.put(1.0, 8.0);
map.put(7.0, 130.0);
map.put(2.0, 4.0);
map.put(3.0, 1.0);
map.put(4.0, 18.0);
map.put(5.0, 160.0);
map.put(6.0, 180.0);
map.put(8.1, 133.5);
tu=new MyTuView(this,map,200,50,"x","y",false);
// tu.setC(Color.CYAN);
tu.setResid(R.drawable.bg);
// tu.setBheight(200);
tu.setTotalvalue(200);

tu.setPjvalue(50);
tu.setXstr("x");
tu.setYstr("y");
tu.setMargint(20);
tu.setBackgroundColor(Color.WHITE);
tu.setMarginb(50);
tu.setMstyle(Mstyle.scroll);
RelativeLayout rela=getlayout(R.layout.activity_main);
rela.addView(tu);
LayoutParams parm=new LayoutParams(1200,400);
parm.setMargins(50, 50, 50, 100);
tu.setLayoutParams(parm);
setContentView(rela);

}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// TODO Auto-generated method stub
if(item.getItemId() == R.id.menu_settings)
{
if (false == tu.isDrawingCacheEnabled())
{
tu.setDrawingCacheEnabled(true);
}
Bitmap bitmap = tu.getDrawingCache();
Tools tool=new Tools();
try {
Boolean b=tool.saveFile(bitmap, "aaaa.png");
if(b)
Toast.makeText(this, "success", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(item.getItemId() == R.id.menu_ch)
{
HashMap map=new HashMap();
map.put(1.0, 21.0);
map.put(3.0, 25.0);
map.put(4.0, 32.0);
map.put(5.0, 31.0);
map.put(6.0, 26.0);

tu.setTotalvalue(40);
tu.setPjvalue(10);
tu.setMap(map);
tu.setIsylineshow(true);
tu.postInvalidate();
}
if(item.getItemId() == R.id.menu_ch2)
{
HashMap map=new HashMap();
map.put(1.0, 41.0);
map.put(3.0, 25.0);
map.put(4.0, 32.0);
map.put(5.0, 41.0);
map.put(6.0, 16.0);
map.put(7.0, 36.0);
map.put(8.0, 26.0);
tu.setTotalvalue(50);
tu.setPjvalue(10);
tu.setMap(map);
tu.setMstyle(Mstyle.Line);
tu.setIsylineshow(false);
tu.postInvalidate();
}
return true;
}

public RelativeLayout getlayout(int r)
{
LayoutInflater inflater = (LayoutInflater)getSystemService(android.content.Context.LAYOUT_INFLATER_SERVICE );
try {
XmlResourceParser parser = getResources().getLayout(r);
RelativeLayout layout = (RelativeLayout) inflater.inflate(parser, null);
return layout;
}catch (Exception e) {
// TODO: handle exception
}
return null;
}
}

⑵ Android的APP,是怎麼做渠道統計的

安卓渠道統計方案

方法1:通常傳統的做法是對不同渠道進行分包發布,每個渠道打一個標識唯一的渠道id的安裝包,再收集渠道安裝數據。這種方式有些弊端,如果渠道很多的話比如說有100個渠道要推廣,就得手工打100個渠道包,這樣做的話技術人員就比較辛苦了。另一個弊端就是應用市場會存在抓包的情況,這樣就會造成數據不準的情況。

方法2:用渠道鏈接替代渠道安裝包做渠道統計,這種方案就可以免去手工打渠道包,而且統計數據會更精確。具體實現請參考openinstall的官網 www.openinstall.io

⑶ android 統計sdk怎麼做

導入Analytics_Android_SDK_3.0.jar(簡稱SDK)
下載最新版sdk的zip包,解壓將其中的Analytics_Android_SDK_3.0.jar釋放到本地目錄,Eclipse用戶右鍵您的工程根目錄,選擇Properties -> Java Build Path -> Libraries, 然後點擊Add External JARs... 選擇指向 Analytics_Android_SDK_3.0.jar 的路徑,點擊OK,即導入成功。

配置AndroidManifest.xml
android.permission.INTERNET 向我們的伺服器發送用戶分析數據。
android.permission.READ_PHONE_STATE 這個許可權僅為了獲取用戶手機的IMEI,用來唯一的標識用戶。(如果您的應用會運行在無法讀取IMEI的平板上,我們會將mac地址作為用戶的唯一標識,請添加許可權: android.permission.ACCESS_WIFI_STATE )

⑷ Android應用統計-使用時長及次數統計(一)

最近在做有關於應用統計有關的工作,主要是統計系統中客戶端應用(非系統自帶的那些基礎應用,比如DownLoadManager),在每一天的使用情況,統計內容包括:應用打開次數,應用合計使用時長等。
在所搜尋的方案中,大致有如下兩種:

以下方案採用兩個方案並行,主要是以系統數據統計結果為主,以自行記錄的數據作為參照,用以對比兩組數據,以保證數據統計結果的有效性和穩定性。

在Android中,系統會自行記錄應用的打開次數和使用時間,且提供了相關api於開發者,但是每一次版本提升都可能會對api帶來相當大的改變,這一塊也不例外。但是始終沒有變化的就是在撥號鍵盤輸入* # * #4636# * #*,進入工程模式,點擊「使用情況統計數據」,你就可以看到統計界面了。由於各個版本之間差異比較大,而且相關的資料也比較少,本次使用的api以及相關的說明都是以Android-5.1為基礎。在某些版本中,應用統計api,存在不少缺陷以及避坑的地方,尤其是手機廠家修改過源碼之後,所以對於某些品牌的測試機器,程序的運行結果會有一點不一樣,請各位讀者有所注意。

本文主要介紹了關於Android系統中統計各個app的使用情況的解決方案,以及獲取相關數據的方法。關於系統記錄的數據的原理以及在該原理的邏輯下可能出現的bug,將會在接下來的文章中詳細闡述。

github: UseTimeStatistic
參考文獻:
Android 5.0以上通過UsageStatsManager類 獲取應用使用情況(精品)
android如何獲取系統里各個應用的使用時間?
Android UsageStatsService:要點解析
Android5.1應用打開次數獲取

下一篇:Android應用統計-使用時長及次數統計(二)

⑸ 手機android 編程怎麼畫出折線統計圖

後來發現一個更加強大的開源框架MPAndroidChart。

下面簡單介紹下MPAndroidChart,MPAndroidChart的效果還是蠻好的,提供各種動畫,這個也是我使用MPAndroidChart,而且放棄achartengine的原因。

Github地址連接,後面是youtube上面演示MPAndroidChart的視頻,MPAndroidChart由於提供了動畫效果,為了兼容低版本的Android系統,MPAndroidChart需要添加nineoldandroids-2.4.0-2.jar作為依賴庫,所以如果項目中使用這個表格庫,需要同時導入這個兩個jar,當然如果使用libproject的方式,就不用了。

核心功能:

支持x,y軸縮放

支持拖拽

支持手指滑動

支持高亮顯示

支持保存圖表到文件中

支持從文件(txt)中讀取數據

預先定義顏色模板

自動生成標注

支持自定義x,y軸的顯示標簽

支持x,y軸動畫

支持x,y軸設置最大值和附加信息

支持自定義字體,顏色,背景,手勢,虛線等

顯示的圖表類型:

LineChart (with legend, simple design) (線性圖)

⑹ 如何統計Android手機各個應用的使用時間以及使用次數

一:通過反射com.android.internal.os.PkgUsageStats來獲取你想要的信息

二:應用的啟動大部分應該都是在桌面上點擊從而啟動的,所以可以在桌面launcher中做統計處理,也可以把統計數據共享給某個應用。
望採納

閱讀全文

與android統計庫相關的資料

熱點內容
ie9文件夾怎麼查看ftp 瀏覽:62
唯品會python解密 瀏覽:852
安卓高拍儀有什麼用 瀏覽:241
同步盤用什麼app好 瀏覽:188
伺服器上下載是什麼意思 瀏覽:169
s6怎麼接電話加密 瀏覽:152
電腦的命令指令符打不開怎麼辦 瀏覽:534
可編程邏輯器件cpld開發板 瀏覽:888
加裝文件夾圖片 瀏覽:425
27歲程序員offer 瀏覽:619
中國建築史梁思成pdf 瀏覽:198
單片機雙核與單核區別 瀏覽:850
xss攻擊需要編譯的符號 瀏覽:140
南京單片機定址 瀏覽:897
自製西門子編程電纜 瀏覽:807
伺服器還叫什麼名 瀏覽:712
空氣壓縮機阿特拉斯 瀏覽:906
數控加工螺紋零件圖及編程 瀏覽:402
和平精英安卓怎麼改90幀 瀏覽:306
程序員寫的詩 瀏覽:230