Skip to content

Commit 18e87f0

Browse files
committed
Merge branch 'codex/create-building.md-for-codename-one-o1r15v' of https://github.com/codenameone/CodenameOne into codex/create-building.md-for-codename-one-o1r15v
2 parents 151c671 + f979ae1 commit 18e87f0

File tree

10 files changed

+143
-66
lines changed

10 files changed

+143
-66
lines changed

.github/workflows/ant.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Build with Maven
2323
run: |
2424
cd maven
25-
xvfb-run -a mvn install
25+
xvfb-run -a mvn install -Plocal-dev-javase
2626
2727
2828
- name: Fetch archetype projects
@@ -34,8 +34,8 @@ jobs:
3434
run: |
3535
unzip cn1-maven-archetypes.zip
3636
cd cn1-maven-archetypes-master
37-
xvfb-run -a mvn install archetype:update-local-catalog
38-
xvfb-run -a mvn archetype:crawl
37+
xvfb-run -a mvn install archetype:update-local-catalog -Plocal-dev-javase
38+
xvfb-run -a mvn archetype:crawl -Plocal-dev-javase
3939
- name: Run Maven Unit Tests
4040
run: |
4141
pwd

.github/workflows/pr.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Run Unit Tests
3737
run: |
3838
cd maven
39-
mvn clean verify -DunitTests=true -pl core-unittests -am -Dmaven.javadoc.skip=true
39+
mvn clean verify -DunitTests=true -pl core-unittests -am -Dmaven.javadoc.skip=true -Plocal-dev-javase
4040
cd ..
4141
- name: Install dependencies
4242
run: |
@@ -59,8 +59,8 @@ jobs:
5959
mkdir -p build/tempJavaSources
6060
mkdir -p dist
6161
mkdir -p dist/javadoc
62-
wget https://github.com/codenameone/JavaDocSourceEmbed/releases/download/refs%2Fheads%2Fmaster/JavaDocSourceEmbed-1.0-SNAPSHOT.jar
63-
java -jar JavaDocSourceEmbed-1.0-SNAPSHOT.jar src build/tempJavaSources
62+
# Skip JavaDocSourceEmbed due to gist access issues in CI
63+
cp -r src/* build/tempJavaSources/
6464
find build/tempJavaSources ../Ports/CLDC11/src -name "*.java" | /usr/bin/grep -v /impl/ | /usr/bin/xargs javadoc --allow-script-in-comments -protected -d dist/javadoc -windowtitle "Codename One API" || true
6565
cd dist/javadoc
6666
zip -r ../../javadocs.zip *

.github/workflows/release-on-maven-central.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ jobs:
2525
git config --global user.name "GitHub Actions Bot"
2626
git config --global user.email "[email protected]"
2727
28+
- name: Check Maven Version
29+
run: mvn -v
30+
2831
- name: Deploy with Maven
2932
run: |
3033
cat $HOME/.m2/settings.xml
3134
cd maven
3235
bash update-version.sh "$GITHUB_REF_NAME"
3336
export GPG_TTY=$(tty)
34-
xvfb-run -a mvn deploy -Psign-artifacts -Dgpg.passphrase=$MAVEN_GPG_PASSPHRASE
37+
xvfb-run -a mvn deploy -Psign-artifacts -Dgpg.passphrase=$MAVEN_GPG_PASSPHRASE -Plocal-dev-javase
3538
cd ..
3639
git clone https://github.com/shannah/cn1-maven-archetypes
3740
cd cn1-maven-archetypes
3841
bash update-version.sh "$GITHUB_REF_NAME"
39-
xvfb-run -a mvn deploy -Psign-artifacts -Dgpg.passphrase=$MAVEN_GPG_PASSPHRASE
42+
xvfb-run -a mvn deploy -Psign-artifacts -Dgpg.passphrase=$MAVEN_GPG_PASSPHRASE -Plocal-dev-javase
4043
env:
4144
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
4245
MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,4 @@ pom.xml.versionsBackup
7070
pom.xml.releaseBackup
7171
pom.xml.tag
7272
!maven/**/*.zip
73-
/tools/
74-
tools.sh
73+
**/.flattened-pom.xml

CodenameOne/src/com/codename1/components/ImageViewer.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,26 @@ private void updatePositions() {
503503
imageDrawHeight = prefH;
504504
imageX = prefX;
505505
imageY = prefY;
506-
cropBox.set(-imageY/(double)imageDrawHeight, (imageX + imageDrawWidth - getWidth())/(double)imageDrawWidth, (imageY + imageDrawHeight - getHeight())/(double)imageDrawHeight, -imageX/(double)imageDrawWidth);
506+
507+
// Apply the same constraints used in paint() method to ensure cropBox matches what's actually visible
508+
int constrainedImageX = imageX;
509+
int constrainedImageY = imageY;
510+
511+
if (imageDrawWidth > getInnerWidth()) {
512+
constrainedImageX = Math.max(
513+
Math.min(0, imageX),
514+
-imageDrawWidth + getInnerWidth()
515+
);
516+
}
517+
518+
if (imageDrawHeight > getInnerHeight()) {
519+
constrainedImageY = Math.max(
520+
Math.min(0, imageY),
521+
-imageDrawHeight + getInnerHeight()
522+
);
523+
}
524+
525+
cropBox.set(-constrainedImageY/(double)imageDrawHeight, (constrainedImageX + imageDrawWidth - getWidth())/(double)imageDrawWidth, (constrainedImageY + imageDrawHeight - getHeight())/(double)imageDrawHeight, -constrainedImageX/(double)imageDrawWidth);
507526
return;
508527
}
509528
int iW = image.getWidth();
@@ -529,7 +548,26 @@ private void updatePositions() {
529548

530549
imageY += (getInnerHeight() - imageDrawHeight)/2;
531550
}
532-
cropBox.set(-imageY/(double)imageDrawHeight, (imageX + imageDrawWidth - getWidth())/(double)imageDrawWidth, (imageY + imageDrawHeight - getHeight())/(double)imageDrawHeight, -imageX/(double)imageDrawWidth);
551+
552+
// Apply the same constraints used in paint() method to ensure cropBox matches what's actually visible
553+
int constrainedImageX = imageX;
554+
int constrainedImageY = imageY;
555+
556+
if (imageDrawWidth > getInnerWidth()) {
557+
constrainedImageX = Math.max(
558+
Math.min(0, imageX),
559+
-imageDrawWidth + getInnerWidth()
560+
);
561+
}
562+
563+
if (imageDrawHeight > getInnerHeight()) {
564+
constrainedImageY = Math.max(
565+
Math.min(0, imageY),
566+
-imageDrawHeight + getInnerHeight()
567+
);
568+
}
569+
570+
cropBox.set(-constrainedImageY/(double)imageDrawHeight, (constrainedImageX + imageDrawWidth - getWidth())/(double)imageDrawWidth, (constrainedImageY + imageDrawHeight - getHeight())/(double)imageDrawHeight, -constrainedImageX/(double)imageDrawWidth);
533571
}
534572

535573
/**

Ports/Android/src/com/codename1/impl/android/AndroidImplementation.java

Lines changed: 67 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8006,19 +8006,27 @@ private String getImageFilePath(Uri uri) {
80068006
//String[] filePaths = file.getPath().split(":");
80078007
//String image_id = filePath[filePath.length - 1];
80088008
String[] filePathColumn = {MediaStore.Images.Media.DATA};
8009-
Cursor cursor = getContext().getContentResolver().query(
8010-
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
8011-
new String[]{ MediaStore.Images.Media.DATA},
8012-
null,
8013-
null,
8014-
null
8015-
);
8016-
cursor.moveToFirst();
8017-
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
8018-
String filePath = cursor.getString(columnIndex);
8019-
cursor.close();
8020-
8021-
if (filePath == null || "content".equals(scheme)) {
8009+
Cursor cursor = getContext().getContentResolver().query(
8010+
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
8011+
new String[]{ MediaStore.Images.Media.DATA},
8012+
null,
8013+
null,
8014+
null
8015+
);
8016+
// Some gallery providers may return an empty cursor on modern Android builds.
8017+
String filePath = null;
8018+
if (cursor != null) {
8019+
try {
8020+
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
8021+
if (columnIndex >= 0 && cursor.moveToFirst()) {
8022+
filePath = cursor.getString(columnIndex);
8023+
}
8024+
} finally {
8025+
cursor.close();
8026+
}
8027+
}
8028+
8029+
if (filePath == null || "content".equals(scheme)) {
80228030
//if the file is not on the filesystem download it and save it
80238031
//locally
80248032
try {
@@ -8159,24 +8167,26 @@ else if (requestCode == FILECHOOSER_RESULTCODE) {
81598167
Uri selectedImage = intent.getData();
81608168
String scheme = intent.getScheme();
81618169

8162-
String[] filePathColumn = {MediaStore.Images.Media.DATA};
8163-
Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
8164-
8165-
// this happens on Android devices, not exactly sure what the use case is
8166-
if(cursor == null) {
8167-
callback.fireActionEvent(null);
8168-
return;
8169-
}
8170-
8171-
cursor.moveToFirst();
8172-
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
8173-
String filePath = cursor.getString(columnIndex);
8174-
cursor.close();
8175-
boolean fileExists = false;
8176-
if (filePath != null) {
8177-
File file = new File(filePath);
8178-
fileExists = file.exists() && file.canRead();
8179-
}
8170+
String[] filePathColumn = {MediaStore.Images.Media.DATA};
8171+
Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
8172+
8173+
// Some gallery providers may return an empty cursor on modern Android builds.
8174+
String filePath = null;
8175+
if (cursor != null) {
8176+
try {
8177+
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
8178+
if (columnIndex >= 0 && cursor.moveToFirst()) {
8179+
filePath = cursor.getString(columnIndex);
8180+
}
8181+
} finally {
8182+
cursor.close();
8183+
}
8184+
}
8185+
boolean fileExists = false;
8186+
if (filePath != null) {
8187+
File file = new File(filePath);
8188+
fileExists = file.exists() && file.canRead();
8189+
}
81808190

81818191
if (!fileExists && "content".equals(scheme)) {
81828192
//if the file is not on the filesystem download it and save it
@@ -8204,26 +8214,33 @@ else if (requestCode == FILECHOOSER_RESULTCODE) {
82048214
}
82058215
}
82068216

8207-
callback.fireActionEvent(new ActionEvent(new String[]{filePath}));
8208-
return;
8217+
if (filePath == null) {
8218+
callback.fireActionEvent(null);
8219+
return;
8220+
}
8221+
8222+
callback.fireActionEvent(new ActionEvent(new String[]{filePath}));
8223+
return;
82098224
} else if (requestCode == OPEN_GALLERY) {
82108225

82118226
Uri selectedImage = intent.getData();
82128227
String scheme = intent.getScheme();
82138228

8214-
String[] filePathColumn = {MediaStore.Images.Media.DATA};
8215-
Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
8216-
8217-
// this happens on Android devices, not exactly sure what the use case is
8218-
if(cursor == null) {
8219-
callback.fireActionEvent(null);
8220-
return;
8229+
String[] filePathColumn = {MediaStore.Images.Media.DATA};
8230+
Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
8231+
8232+
// Some gallery providers may return an empty cursor on modern Android builds.
8233+
String filePath = null;
8234+
if (cursor != null) {
8235+
try {
8236+
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
8237+
if (columnIndex >= 0 && cursor.moveToFirst()) {
8238+
filePath = cursor.getString(columnIndex);
8239+
}
8240+
} finally {
8241+
cursor.close();
8242+
}
82218243
}
8222-
8223-
cursor.moveToFirst();
8224-
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
8225-
String filePath = cursor.getString(columnIndex);
8226-
cursor.close();
82278244
boolean fileExists = false;
82288245
if (filePath != null) {
82298246
File file = new File(filePath);
@@ -8256,6 +8273,11 @@ else if (requestCode == FILECHOOSER_RESULTCODE) {
82568273
}
82578274
}
82588275

8276+
if (filePath == null) {
8277+
callback.fireActionEvent(null);
8278+
return;
8279+
}
8280+
82598281
callback.fireActionEvent(new ActionEvent(filePath));
82608282
return;
82618283
} else {

Ports/Android/src/com/codename1/social/GoogleImpl.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
113113
String displayName = acct.getDisplayName();
114114
String acctId = acct.getId();
115115
String email = acct.getEmail();
116-
String requestIdToken = acct.getIdToken();
116+
final String requestIdToken = acct.getIdToken();
117117
Set<Scope> grantedScopes = acct.getGrantedScopes();
118118
String code = acct.getServerAuthCode();
119119
String scopeStr = scope;
@@ -133,7 +133,14 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
133133
protected void readResponse(InputStream input) throws IOException {
134134
Map<String, Object> json = new JSONParser().parseJSON(new InputStreamReader(input, "UTF-8"));
135135
if (json.containsKey("access_token")) {
136-
setAccessToken(new AccessToken((String) json.get("access_token"), (String)null));
136+
String accessToken = (String) json.get("access_token");
137+
String expiresIn = json.containsKey("expires_in") ? String.valueOf(json.get("expires_in")) : null;
138+
String refreshToken = json.containsKey("refresh_token") ? (String) json.get("refresh_token") : null;
139+
String idToken = json.containsKey("id_token") ? (String) json.get("id_token") : requestIdToken;
140+
141+
// Use the constructor that includes all token fields
142+
setAccessToken(new AccessToken(accessToken, expiresIn, refreshToken, idToken));
143+
137144
Display.getInstance().callSerially(new Runnable() {
138145

139146
@Override
@@ -142,7 +149,9 @@ public void run() {
142149
}
143150
});
144151
} else {
145-
setAccessToken(new AccessToken());
152+
// Even if we don't get an access token from the server, we can still set the ID token
153+
// that we received from the initial Google Sign-In
154+
setAccessToken(new AccessToken(null, null, null, requestIdToken));
146155
Log.p("Failed to retrieve the access token from the google auth server. Login succeeded, but access token is null, so you won't be able to use it to retrieve additional information.");
147156
Log.p("Response was " + json);
148157
Display.getInstance().callSerially(new Runnable() {
@@ -168,7 +177,8 @@ public void run() {
168177
req.setReadResponseForErrors(true);
169178
NetworkManager.getInstance().addToQueue(req);
170179
} else {
171-
setAccessToken(new AccessToken());
180+
// Even without clientId and clientSecret, we should still preserve the ID token from the initial sign-in
181+
setAccessToken(new AccessToken(null, null, null, requestIdToken));
172182
Log.p("The access token was set to null because one of clientId, clientSecret, requestIdToken, or auth were null");
173183
Log.p("The login succeeded, but you won't be able to make any requests to Google's REST apis using the login token.");
174184
Log.p("In order to obtain a token that can be used with Google's REST APIs, you need to set the clientId, and clientSecret of" +

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ The setup is covered in depth in [this article and video](https://www.codenameon
185185
~~~~
186186
git clone https://github.com/codenameone/CodenameOne
187187
cd CodenameOne/maven
188-
mvn install
188+
mvn install -Plocal-dev-javase
189189
~~~~
190190

191+
NOTE: The `-Plocal-dev-javase` profile is necessary for building the javase port. Without it, you'll get build errors.
192+
191193
This will build and install Codename One in your local Maven repository. This process can take a while since it automatically downloads dependencies with a size of ~1GB.
192194

193195

@@ -196,15 +198,15 @@ To build the archetype projects from source, you should check out the [cn1-maven
196198
~~~~
197199
git clone https://github.com/shannah/cn1-maven-archetypes
198200
cd cn1-maven-archetypes
199-
mvn install
201+
mvn install -Plocal-dev-javase
200202
~~~~
201203

202204

203205
Now that Codename One is installed in your local Maven repository, you can use that version in a project instead of the release version.
204206
A new testing project can be quickly generated with the [Codename One initializr](https://start.codenameone.com).
205207

206208
After downloading and extracting the project, open its pom.xml file and and look for the `<cn1.version>` and `<cn1.plugin.version>` properties.
207-
Then change these to point to the version that got installed into your *local* maven repository by `mvn install`. The locally built version will usually be a SNAPSHOT version (e.g. 7.0.21-SNAPSHOT).
209+
Then change these to point to the version that got installed into your *local* maven repository by `mvn install -Plocal-dev-javase`. The locally built version will usually be a SNAPSHOT version (e.g. 7.0.21-SNAPSHOT).
208210

209211

210212
### Quick Start with Ant

maven/javase/pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@
5353
<profile>
5454
<id>local-dev-javase</id>
5555
<activation>
56-
<activeByDefault>true</activeByDefault>
56+
<property>
57+
<name>codename1.platform</name>
58+
<value>javase</value>
59+
</property>
5760
</activation>
5861
<dependencies>
5962
<dependency>

maven/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@
409409
<plugin>
410410
<groupId>org.sonatype.central</groupId>
411411
<artifactId>central-publishing-maven-plugin</artifactId>
412-
<version>0.7.0</version>
412+
<version>0.8.0</version>
413413
<extensions>true</extensions>
414414
<configuration>
415415
<publishingServerId>central</publishingServerId>

0 commit comments

Comments
 (0)