質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

1回答

974閲覧

bitmap()の使い方(聞きたいことはプログラムの並び順だけです。)

H30_inenaga

総合スコア18

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2019/01/02 09:30

編集2022/01/12 10:55

知りたいこと

javaが苦手で、以下に乗せるソースコードのrenderObjが赤字でエラーになっています。
おそらくプログラムの並び順が悪いと思うので、正しい並び順を教えていただけないでしょうか?
(もしくは、他の関数に入れる?)
このソースは、MainActivityにまるごと入れていますが、他のクラスを作って方が良いのでしょうか?
色々調べましたら、SmartEyeglassControlUtilsのオブジェクトであるUtilsが正常に機能しておらず、UtilsにかかるUtils.●●が赤字になっているようです。
オブジェクトが使えない原因がよく分かりません。。。
SmartEyeGlassControlUtils.java(ソースコード追加しました。)には、setRequiredApiVersionやactivateやregisterARObjectなどMainActivityで使うクラスの中身はあるのですが、
MainActivityの方で、
private final SmartEyeglassControlUtils utils;
utils=new SmartEyeglassControlUtils(hostAppPackageName,listener);
として、オブジェクトUtilsを作成し、SmartEyeGlassControlUtils.javaの中のクラスを使えるようになるはずですが、いざUtils.とピリオドを打つと、PointInWorldCoordinateしか表示されません。
PointInWorldCoordinateは、SmartEyeGlassControlUtils.javaの中ではクラスなようです。
少しずつ追記していきますし、真剣に悩んでいるので、少しでも助言ください!

ソースコード(並び順が悪い?)

Java

1 //ARイベント用ハンドラーであるSmartEyeglassEventListenerの登録 2 private final SmartEyeglassEventListener listener = new SmartEyeglassEventListener() { 3 @Override 4 public void onARRegistrationResult( 5 final int result, final int objectId) { 6 if (result != SmartEyeglassControl.Intents.AR_RESULT_OK) { 7 return; 8 } 9 } 10 11 // Find bitmap to render when requested by AR engine 12 @Override 13 public void onARObjectRequest(final int objectId) { 14 15 // send bitmap 16 utils.sendARObjectResponse(renderObj, 0); 17 } 18 }; 19 //そしてSmartEyeglassControlUtilsのオブジェクトを生成し、初期設定 20 private final SmartEyeglassControlUtils utils; 21 utils=new SmartEyeglassControlUtils(hostAppPackageName,listener); 22 utils.setRequiredApiVersion(SMARTEYEGLASS_API_VERSION); 23 utils.activate(context); 24 25//imageMapにbitmapを登録 26//画像はbitmapにしてSmartEyeGlassに表示される 27//まずは、bitmapを複数格納する配列を用意する 28 29private SparseArray<Bitmap> imageMap=new SparseArray<Bitmap>(); 30//このimageMapにbitmapを入れる 31 32// 配列の番号(キー) 33 int key; 34// skiplace.pngが/res/drawable下にあるものとする 35 imageMap.put(key,R.drawable.skiplace)); 36 Bitmap b=BitmapFactory.decodeResource(context.getResources(),R.drawable.skiplace); 37 b.setDensity(DisplayMetrics.DENSITY_DEFAULT); 38 39 40 // SmartEyeglassに画像を表示 41 RenderObject renderObj=new RenderObject(OBJECT_ID,getBitmapResource(R.drawable.skiplace),0,0){ 42@Override 43public void toMoveExtras(Intent intent){ 44 } 45 }; 46 this.utils.registerARObject(renderObj); 47//そして、bitmapを表示する 48// 欲しいbitmapのキー 49 int num=0; 50private static final int OBJECT_ID=1; 51 52 Bitmap bitmap=imageMap.get(num); 53 utils.showBitmap(bitmap);

ソースコード(SmartEyeGlassControlUtils)

※少し長いです。

Java

1import2 private static final List<Integer> RENDER_MODE = Arrays.asList( 3 SmartEyeglassControl.Intents.MODE_NORMAL, 4 SmartEyeglassControl.Intents.MODE_AR 5 ); 6 7 private Context mContext; 8 private final String mHostAppPackageName; 9 private final BitmapFactory.Options mBitmapOptions; 10 private int mRenderingMode = SmartEyeglassControl.Intents.MODE_NORMAL; 11 12 private final Handler mHandler; 13 private final SmartEyeglassEventListener mGeneralEventListener; 14 private int mSetApiVersion = 0; 15 private boolean mCameraStarted = false; 16 17 public SmartEyeglassControlUtils(String hostAppPackageName, 18 SmartEyeglassEventListener eventListener) { 19 mHostAppPackageName = hostAppPackageName; 20 mHandler = new Handler(); 21 22 if (eventListener != null) { 23 mGeneralEventListener = eventListener; 24 } else { 25 mGeneralEventListener = new SmartEyeglassEventListener(); 26 } 27  mBitmapOptions = new BitmapFactory.Options(); 28 mBitmapOptions.inDensity = DisplayMetrics.DENSITY_DEFAULT; 29 mBitmapOptions.inTargetDensity = DisplayMetrics.DENSITY_DEFAULT; 30 } 31 public final void activate(final Context context) { 32 if (mContext != null) { 33 deactivate(); 34 } 35 mContext = context; 36 37 // register BroadcastReceiver 38 IntentFilter filter = new IntentFilter(); 39 filter.addAction(SmartEyeglassControl.Intents.CONTROL_AR_GET_OBJECT_REQUEST_INTENT); 40 filter.addAction(SmartEyeglassControl.Intents.CONTROL_AR_REGISTER_OBJECT_RESPONSE_INTENT); 41 context.registerReceiver(this, filter); 42 43 sendConfirmApiVersion(context); 44 } 45 46 47 public final void deactivate() { 48 if (mContext == null) { 49 return; 50 } 51 mContext.unregisterReceiver(this); 52 mContext = null; 53 } 54 55 private class IntentRunner implements Runnable { 56 protected Intent mIntent; 57 IntentRunner(Intent intent) { 58 mIntent = intent; 59 } 60 61 @Override 62 public void run() { 63 } 64 } 65 66 @Override 67 public void onReceive(Context context, Intent intent) { 68 mHandler.post(new IntentRunner(intent) { 69 @Override 70 public void run() { 71 String action = mIntent.getAction(); 72 if (action == null) { 73 return; 74 } 75 private void sendConfirmApiVersion(final Context context) { 76 int apiVersion = context.getResources().getInteger(R.integer.api_version); 77 78 if (apiVersion < mSetApiVersion) { 79 throw new IllegalArgumentException( 80 context.getResources().getString(R.string.api_version_error_throw_message)); 81 } 82 83 if (mSetApiVersion == 0) { 84 mSetApiVersion = apiVersion; 85 } 86 87 Intent intent = new Intent(SmartEyeglassControl.Intents.CONTROL_API_VERSION_CONFIRM_INTENT); 88 intent.putExtra(SmartEyeglassControl.Intents.EXTRA_VERSION_DATA, mSetApiVersion); 89 90 sendToHostApp(intent); 91 } 92 93 public void setRequiredApiVersion(final int version) { 94 mSetApiVersion = version; 95 } 96 97 Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), resourceId, 98 mBitmapOptions); 99 100 sendDisplayDataWithCallback(bitmap, INVALID_DISP_OFFSET, INVALID_DISP_OFFSET, 101 transactionNumber, SmartEyeglassControl.Intents.DISPLAY_DATA_TYPE_SHOW_IMAGE); 102 } 103 104 public void showBitmap(final Bitmap bitmap) { 105 if (Dbg.DEBUG) { 106 Dbg.d("showBitmap"); 107 } 108 109 sendDisplayData(bitmap, INVALID_DISP_OFFSET, INVALID_DISP_OFFSET); 110 } 111 112 public void showBitmap(final Bitmap bitmap, final int x, final int y) { 113 if (Dbg.DEBUG) { 114 Dbg.v("showBitmap x: " + x + " y: " + y); 115 } 116 117 sendDisplayData(bitmap, x, y); 118 } 119 120 public void registerARObject(final RenderObject object) { 121 if (mRenderingMode != SmartEyeglassControl.Intents.MODE_AR) { 122 // error, not in AR mode so operation not possible 123 throw new IllegalStateException("Not in AR mode"); 124 } 125 126 if (object == null) { 127 throw new IllegalArgumentException("object has illegal value"); 128 } 129 130 Intent intent = new Intent(SmartEyeglassControl.Intents.CONTROL_AR_REGISTER_OBJECT_REQUEST_INTENT); 131 object.toRegisterExtras(intent); 132 133 sendToHostApp(intent); 134 } 135 public class PointInWorldCoordinate { 136 public double latitude; 137 public double longitude; 138 public double altitude; 139 } 140 public static PointF convertCoordinateSystemFromWorldToCylindrical( 141 final PointInWorldCoordinate viewingLocation, 142 final PointInWorldCoordinate targetLocation) { 143 PointF point = new PointF(); 144 float[] results = {0, 0, 0}; 145 146 Location.distanceBetween(viewingLocation.latitude, viewingLocation.longitude, 147 targetLocation.latitude, targetLocation.longitude, results); 148 float distance = results[0]; 149 double angle = getAngle(viewingLocation.altitude, targetLocation.altitude, distance); 150 int direction = getPosDirection(viewingLocation.latitude, viewingLocation.longitude, 151 targetLocation.latitude, targetLocation.longitude); 152 153 point.set((float) direction, (float) angle); 154 155 return point; 156 } 157}

参考文献

http://korechi.hatenablog.com/entry/2016/03/25/023434

よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

maisumakun

2019/01/02 09:50

エラーメッセージはどのようなものでしょうか。
keicha_hrs

2019/01/02 10:36 編集

これはコードを部分的に提示されたものだと思うのですが、インデントのレベルが不正確のように思えます。Android Studioで編集しているのなら、そのコードエディター上からそのままコピーペーストすれば行頭空白も保たれるはずなのですが、敢えて除去して転載されているのでしょうか。これではrenderObjが何かのメソッドの中で宣言されている変数なのか、フィールドなのかの判別もできません。
H30_inenaga

2019/01/02 11:52

インデント整理をしました。
H30_inenaga

2019/01/03 13:52

エラーメッセージは、 Missing method body , decrare abstract Cannnot resolve symbol 'renderobJ' ※'renderobJ'は、hostAppPackageNameなどが入り、それらが赤字でエラーメッセージとなっています。
guest

回答1

0

//skiplace.pngが/res/drawable下にあるものとする
imageMap.put(key,R.drawable.skiplace));

↑の「));」の閉じ括弧が多いような気がするのですが、どうでしょうか。
対応しているものが見つからない気がします。

他の人も指摘していますが、インデントが不正確な為非常に見にくいです。

投稿2019/01/08 06:45

ronin

総合スコア89

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

H30_inenaga

2019/01/08 06:58

インデント整理を自分なりにしてみましたが・・・ どのようにやるのが良いのでしょうか?
ronin

2019/01/08 07:04

統合開発環境をご利用ならフォーマッターがあると思いますが、それを利用されたらいかがでしょうか。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問