Android ZXing QR 読み取りのセンターラインを消すには?

カスタムレイアウトを有効にする

    <com.journeyapps.barcodescanner.DecoratedBarcodeView
        android:id="@+id/barcode_scanner"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_above="@+id/buttonsLayout"
        app:zxing_scanner_layout="@layout/custom_barcode_scanner"
        android:layout_alignParentTop="true">

フォーカスサイズを変更する

    <com.journeyapps.barcodescanner.BarcodeView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/zxing_barcode_surface"
        app:zxing_framing_rect_width="150dp"
        app:zxing_framing_rect_height="150dp"/>

中央ラインをけす

   <com.journeyapps.barcodescanner.ViewfinderView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/zxing_viewfinder_view"
        app:zxing_possible_result_points="@color/zxing_custom_possible_result_points"
        app:zxing_result_view="@color/zxing_custom_result_view"
        app:zxing_viewfinder_laser="@color/zxing_custom_viewfinder_laser"
        app:zxing_viewfinder_mask="@color/zxing_custom_viewfinder_mask"/>

   <com.journeyapps.barcodescanner.ViewfinderView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/zxing_viewfinder_view"
        app:zxing_possible_result_points="@color/zxing_transparent"
        app:zxing_result_view="@color/zxing_custom_result_view"
        app:zxing_viewfinder_laser="@color/zxing_custom_viewfinder_laser"
        app:zxing_viewfinder_mask="@color/zxing_custom_viewfinder_mask"/>

app:zxing_possible_result_point を透明にする

バックグランドを暗くするには、以下のマスクを変更

  <color name="zxing_custom_viewfinder_mask">#90000000</color>

途中で検地されて出る青い点を消すときは

        app:zxing_viewfinder_laser="@color/zxing_transparent"

権限確認、覚書

権限がないときは、ダイアログを出して促す
ユーザーが権限を許すときは、設定画面に遷移する
権限が不足していれば、アプリ終了しますからね!

public class InitActivity extends AppCompatActivity {

    final static String [] PERMISSION_LIST =  new String[]{
            Manifest.permission.RECORD_AUDIO,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        checkPermission();
    }

    final static int MY_PERMISSIONS_REQUEST = 1;

    void checkPermission() {
        // "今後は確認しない" にチェックがある場合は、ダイアログが表示されずに onRequestPermissionsResult が呼び出される
        ActivityCompat.requestPermissions(this, PERMISSION_LIST, MY_PERMISSIONS_REQUEST);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case MY_PERMISSIONS_REQUEST:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Intent Intent = new Intent(this, MainActivity_.class);
                    startActivity(Intent);
                } else {
                    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    Uri uri = Uri.fromParts("package", getPackageName(), null);
                    intent.setData(uri);
                    startActivity(intent);
                }
                finish();
        }
    }

}

Toolbar の背景色、文字色、サイズを変更するには?

style.xml で指定

   <!-- Customize Application Theme -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Custom background of application -->
        <item name="android:windowBackground">@color/lightGray</item>
        <!-- Toolbar のnavigation & overflow icon の色 -->
        <item name="colorControlNormal">@color/blue_level4</item>
        <item name="windowActionModeOverlay">true</item>
        <!-- Toolar のスタイル -->
        <item name="toolbarStyle">@style/MyApp.Toolbar</item>
    </style>

    <style name="MyApp.Toolbar" parent="Widget.AppCompat.Toolbar">
        <!-- Toolar 背景色 -->
        <item name="android:background">#00FF00</item>
        <item name="titleTextAppearance">@style/MyTextAppearance</item>
    </style>

    <style name="MyTextAppearance" parent="@android:style/TextAppearance.Medium">
        <!-- Text color -->
        <item name="android:textColor">@android:color/white</item>
        <!-- Text size -->
        <item name="android:textSize">5sp</item>
    </style>

android 5.0
Toolbar のバックグランドの色をかえるには?




backgroud で指定

2017年 Android の ORM は、DbFlow に決まったと確信しました。

あまりにも導入しやすいく、あまりにも移行しやすく、あまりにもコードが簡単になる。
感動しました。

自分にとっての ORM はスピードは二の次です。
簡単に管理、コーディング出来ることが最優先です。

Create table やら、OpenDatabase やら、 Open Cursor はもやは不要です。
項目定義もクラス定義することで完了です。
感動です。

なので、使い方を紹介します。
詳しくは
https://www.gitbook.com/book/agrosner/dbflow/details

project gradle

allProjects {
    repositories {
        // required to find the project's artifacts
        maven { url "https://www.jitpack.io" }
    }
}

app gradle

def dbflow_version = "4.0.5"
dependencies {
    apt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
    compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"
    compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}"
}

db class

@Database(name = HatuonDb.NAME, version = HatuonDb.VERSION, generatedClassSeparator = "_")
public class HatuonDb {
    public static final String NAME = "pronunce";
    public static final int VERSION = 1;

}

table class

@Table(database = HatuonDb.class, name="T_WORD")
public class Word extends BaseModel {
    @PrimaryKey(autoincrement = true)
     public long id;

    @Column
    public String word;
    @Column
    public String type;
    @Column
    public String kigou;
    @Column
    public int ngCount;
    @Column
    public int okCount;
    @Column
    public int average;
    @Column
    public String japanese;

    @Column
    public long createdTimeMillis;
}

application class

必要なのは、FlowManager.init(this); のみ
他のコードは、SD Card に DB を保存する為にコードです。

public class MyApplication extends android.app.Application {

@Override
public void onCreate() {
    super.onCreate();
    // PronunceDbExtract();
    FlowManager.init(this);
}

@Override
public SQLiteDatabase openOrCreateDatabase(String name,
   int mode, SQLiteDatabase.CursorFactory factory) {
    return super.openOrCreateDatabase(getDatabasePath(name).getAbsolutePath(), mode, factory);
}

@Override
public SQLiteDatabase openOrCreateDatabase(String name,
    int mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
    return super.openOrCreateDatabase(getDatabasePath(name).getAbsolutePath(), mode, factory, errorHandler);
}

@Override
public boolean deleteDatabase(String name) {
    return super.deleteDatabase(getDatabasePath(name).getAbsolutePath());
}

@Override
public File getDatabasePath(String name) {
    File file = new File(Environment.getExternalStorageDirectory(), name);
    return file;
}

/*
protected void MyDbExtract() {
    String outFile = Environment.getExternalStorageDirectory() +"/" + HatuonDb.NAME + ".db";
    if(!new File(outFile).exists()) {
        FileUtils.copyAssetsFile(getApplicationContext(), "db/hatuon.db", outFile);
    }
}
*/
}

使い方

// 項目名は、 Table名_item で自動生成してくれる
// select * from word where okCOunt = 0 and ngCount = 0
List list = SQLite.select().from(Word.class).where(Word_Table.okCount.eq(0)).and(Word_Table.ngCount.eq(0)).queryList();

// update word set ngCount = ngcount + 1, average = 50 where id = XXX
Word word = list.get(0);
word.ngCount = word.ngCount + 1;
word.average = 50;
word.save;

// count
int count = SQLite.selectCountOf().from(Word.class).count();

// in
List<String> wordList = Arrays.asList(sentence.split(" "));

List<HatuonKigou> words = new Select().from(HatuonKigou.class)
                                  .where(HatuonKigou_Table.word.in(wordList))
                                  .queryList();
Log2.e( new Select().from(HatuonKigou.class)
                     .where(HatuonKigou_Table.word.in(wordList))
                     .getQuery()
                     .toString());

// delete
String category = "sentence_5";
SQLite.delete().from(Sentence.class).where(Sentence_Table.category.eq(category)).async().execute();
     
// sort + count 
Sentence list = SQLite.select().from(Sentence.class)
                .where()
                .and(Sentence_Table.isWord.eq(isWord))
                .and(Sentence_Table.category.eq(category))
                .orderBy(Sentence_Table.average, true)
                .limit(30)
                .queryList();


詳しくは、こちら

ORM は、色々ありますが、すでに、開発が終了していたり、使うときにさらに別クラス宣言が必要だったり、
導入が面倒だったり、自動生成されるクラスが生成されなかったり、なんか良いのないのかと一生懸命
さがしました。realm も試しましたが、スキーマを静的に変えようとおもってもツールが見つから
なかったりと、そんななかで DbFlow を見つけました。
SQLite なら静的にスキーマを変えるツールもたくさんあるし、楽ちんです。

コードは、半減します。
ぜひお試しあれ

ただ、最大の欠点は、iOS 版が無いんですよね


// ex. dumpExtra(getIntent());
static private void dumpExtra(Intent intent) {
if (intent == null) {
Log.v("dumpExtra", "null");
return;
}
Bundle extras = intent.getExtras();
if (extras != null) {
Iterator<?> it = extras.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
Log.v("dumpExtra", "key: " + key);
}
}
}

祝 初パッド

ASUS MeMO Pad 7 ME572CL 購入

想像以上に使いやすい!

USB デバックで接続するには?

\android-sdk-windows\extras\google\usb_driver\android-sdk-windows\extras\google\usb_driver\android_winusb.inf

以下、追加

%SingleAdbInterface%        = USB_Install, USB\VID_0B05&PID_7773
%CompositeAdbInterface%     = USB_Install, USB\VID_0B05&PID_7773&REV_0232&MI_01
%SingleAdbInterface%        = USB_Install, USB\VID_0B05&PID_7773
%CompositeAdbInterface%     = USB_Install, USB\VID_0B05&PID_7773&REV_0232&MI_01

端末の設定->ソフトウェアバージョン->ビルド番号 何度かクリック


<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:fadingEdgeLength="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

android:fadingEdgeLength=”0dp” 追加

		mGridView.setOnItemLongClickListener( new OnItemLongClickListener() {
			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View v, int pos, long id) {
				mPosition = pos;
				parent.showContextMenu();
			    return true;
			}
		});

android keystore のパスワードを完全にわすれる!

まぁ、よくある事…

でも使用するパスワードはたかがしれてる時にどうぞ?
おもいつく限りのワスワードを wordlist.txt に登録。

http://code.google.com/p/android-keystore-password-recover/downloads/detail?name=AndroidKeystoreBrute.jar&can=4&q=

AndroidKeystoreBrute.jar ダウンロード後、以下実行

java -jar AndroidKeystoreBrute.jar -m 3 -k key.txt -d “wordlist.txt”

だめなら、あたらしくアップする。

© 2024 Falco Tech Blog Suffusion theme by Sayontan Sinha